MCPcopy
hub / github.com/cli/cli / TestAddJSONFlagsSetsAnnotations

Function TestAddJSONFlagsSetsAnnotations

pkg/cmdutil/json_flags_test.go:163–207  ·  view source on GitHub ↗

TestAddJSONFlagsSetsAnnotations asserts that `AddJSONFlags` function adds the appropriate annotation to the command, which could later be used by doc generator functions.

(t *testing.T)

Source from the content-addressed store, hash-verified

161// appropriate annotation to the command, which could later be used by doc
162// generator functions.
163func TestAddJSONFlagsSetsAnnotations(t *testing.T) {
164 tests := []struct {
165 name string
166 cmd *cobra.Command
167 jsonFields []string
168 expectedAnnotations map[string]string
169 }{
170 {
171 name: "empty set of fields",
172 cmd: &cobra.Command{},
173 jsonFields: []string{},
174 expectedAnnotations: nil,
175 },
176 {
177 name: "empty set of fields, with existing annotations",
178 cmd: &cobra.Command{Annotations: map[string]string{"foo": "bar"}},
179 jsonFields: []string{},
180 expectedAnnotations: map[string]string{"foo": "bar"},
181 },
182 {
183 name: "no other annotations",
184 cmd: &cobra.Command{},
185 jsonFields: []string{"few", "json", "fields"},
186 expectedAnnotations: map[string]string{
187 "help:json-fields": "few,json,fields",
188 },
189 },
190 {
191 name: "with existing annotations (ensure no overwrite)",
192 cmd: &cobra.Command{Annotations: map[string]string{"foo": "bar"}},
193 jsonFields: []string{"few", "json", "fields"},
194 expectedAnnotations: map[string]string{
195 "foo": "bar",
196 "help:json-fields": "few,json,fields",
197 },
198 },
199 }
200
201 for _, tt := range tests {
202 t.Run(tt.name, func(t *testing.T) {
203 AddJSONFlags(tt.cmd, nil, tt.jsonFields)
204 assert.Equal(t, tt.expectedAnnotations, tt.cmd.Annotations)
205 })
206 }
207}
208
209func TestAddFormatFlags(t *testing.T) {
210 tests := []struct {

Callers

nothing calls this directly

Calls 3

AddJSONFlagsFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected