MCPcopy Index your code
hub / github.com/cli/cli / Test_parseFields_nested

Function Test_parseFields_nested

pkg/cmd/api/fields_test.go:53–137  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func Test_parseFields_nested(t *testing.T) {
54 ios, stdin, _, _ := iostreams.Test()
55 fmt.Fprint(stdin, "pasted contents")
56
57 opts := ApiOptions{
58 IO: ios,
59 RawFields: []string{
60 "branch[name]=patch-1",
61 "robots[]=Hubot",
62 "robots[]=Dependabot",
63 "labels[][name]=bug",
64 "labels[][color]=red",
65 "labels[][colorOptions][]=red",
66 "labels[][colorOptions][]=blue",
67 "labels[][name]=feature",
68 "labels[][color]=green",
69 "labels[][colorOptions][]=red",
70 "labels[][colorOptions][]=green",
71 "labels[][colorOptions][]=yellow",
72 "nested[][key1][key2][key3]=value",
73 "empty[]",
74 },
75 MagicFields: []string{
76 "branch[protections]=true",
77 "ids[]=123",
78 "ids[]=456",
79 },
80 }
81
82 params, err := parseFields(&opts)
83 if err != nil {
84 t.Fatalf("parseFields error: %v", err)
85 }
86
87 jsonData, err := json.MarshalIndent(params, "", "\t")
88 if err != nil {
89 t.Fatal(err)
90 }
91
92 assert.Equal(t, strings.TrimSuffix(heredoc.Doc(`
93 {
94 "branch": {
95 "name": "patch-1",
96 "protections": true
97 },
98 "empty": [],
99 "ids": [
100 123,
101 456
102 ],
103 "labels": [
104 {
105 "color": "red",
106 "colorOptions": [
107 "red",
108 "blue"
109 ],
110 "name": "bug"

Callers

nothing calls this directly

Calls 3

TestFunction · 0.92
EqualMethod · 0.80
parseFieldsFunction · 0.70

Tested by

no test coverage detected