MCPcopy
hub / github.com/cli/cli / TestAddJSONFlagsWithoutShorthand

Function TestAddJSONFlagsWithoutShorthand

pkg/cmdutil/json_flags_test.go:122–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

120}
121
122func TestAddJSONFlagsWithoutShorthand(t *testing.T) {
123 tests := []struct {
124 name string
125 setFlags func(cmd *cobra.Command)
126 wantFlags map[string]string
127 }{
128 {
129 name: "no conflicting flags",
130 setFlags: func(cmd *cobra.Command) {
131 cmd.Flags().StringP("web", "w", "", "")
132 cmd.Flags().StringP("token", "t", "", "")
133 },
134 wantFlags: map[string]string{
135 "web": "w",
136 "token": "t",
137 "jq": "",
138 "template": "",
139 "json": "",
140 },
141 },
142 }
143 for _, tt := range tests {
144 t.Run(tt.name, func(t *testing.T) {
145
146 cmd := &cobra.Command{Run: func(*cobra.Command, []string) {}}
147 tt.setFlags(cmd)
148
149 AddJSONFlagsWithoutShorthand(cmd, nil, []string{})
150
151 for f, shorthand := range tt.wantFlags {
152 flag := cmd.Flags().Lookup(f)
153 require.NotNil(t, flag)
154 require.Equal(t, shorthand, flag.Shorthand)
155 }
156 })
157 }
158}
159
160// TestAddJSONFlagsSetsAnnotations asserts that `AddJSONFlags` function adds the
161// appropriate annotation to the command, which could later be used by doc

Callers

nothing calls this directly

Calls 3

EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected