MCPcopy
hub / github.com/cli/cli / TestAddJSONFlags

Function TestAddJSONFlags

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

Source from the content-addressed store, hash-verified

15)
16
17func TestAddJSONFlags(t *testing.T) {
18 tests := []struct {
19 name string
20 fields []string
21 args []string
22 wantsExport *jsonExporter
23 wantsError string
24 }{
25 {
26 name: "no JSON flag",
27 fields: []string{},
28 args: []string{},
29 wantsExport: nil,
30 },
31 {
32 name: "empty JSON flag",
33 fields: []string{"one", "two"},
34 args: []string{"--json"},
35 wantsExport: nil,
36 wantsError: "Specify one or more comma-separated fields for `--json`:\n one\n two",
37 },
38 {
39 name: "invalid JSON field",
40 fields: []string{"id", "number"},
41 args: []string{"--json", "idontexist"},
42 wantsExport: nil,
43 wantsError: "Unknown JSON field: \"idontexist\"\nAvailable fields:\n id\n number",
44 },
45 {
46 name: "cannot combine --json with --web",
47 fields: []string{"id", "number", "title"},
48 args: []string{"--json", "id", "--web"},
49 wantsExport: nil,
50 wantsError: "cannot use `--web` with `--json`",
51 },
52 {
53 name: "cannot use --jq without --json",
54 fields: []string{},
55 args: []string{"--jq", ".number"},
56 wantsExport: nil,
57 wantsError: "cannot use `--jq` without specifying `--json`",
58 },
59 {
60 name: "cannot use --template without --json",
61 fields: []string{},
62 args: []string{"--template", "{{.number}}"},
63 wantsExport: nil,
64 wantsError: "cannot use `--template` without specifying `--json`",
65 },
66 {
67 name: "with JSON fields",
68 fields: []string{"id", "number", "title"},
69 args: []string{"--json", "number,title"},
70 wantsExport: &jsonExporter{
71 fields: []string{"number", "title"},
72 filter: "",
73 template: "",
74 },

Callers

nothing calls this directly

Calls 3

AddJSONFlagsFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected