MCPcopy
hub / github.com/larksuite/cli / TestParseJSONMap

Function TestParseJSONMap

internal/cmdutil/json_test.go:77–115  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

75}
76
77func TestParseJSONMap(t *testing.T) {
78 fio := &localfileio.LocalFileIO{}
79 tests := []struct {
80 name string
81 input string
82 label string
83 wantLen int
84 wantErr bool
85 }{
86 {"empty input", "", "--params", 0, false},
87 {"json null", "null", "--params", 0, false},
88 {"valid json", `{"a":"1","b":"2"}`, "--params", 2, false},
89 {"invalid json", `{bad}`, "--params", 0, true},
90 {"json array", `[1,2]`, "--data", 0, true},
91 {"unreadable @file", "@/nonexistent/params.json", "--params", 0, true},
92 }
93 for _, tt := range tests {
94 t.Run(tt.name, func(t *testing.T) {
95 got, err := ParseJSONMap(tt.input, tt.label, nil, fio)
96 if (err != nil) != tt.wantErr {
97 t.Errorf("ParseJSONMap() error = %v, wantErr %v", err, tt.wantErr)
98 return
99 }
100 if tt.wantErr {
101 requireJSONInputValidationError(t, err, tt.label)
102 return
103 }
104 if len(got) != tt.wantLen {
105 t.Errorf("ParseJSONMap() returned map with %d keys, want %d", len(got), tt.wantLen)
106 }
107 // A successful parse must yield a non-nil, writable map: callers
108 // overlay onto it (params[k]=v), so `null` — which unmarshals to a
109 // nil map without error — must normalize to {} like empty input.
110 if !tt.wantErr && got == nil {
111 t.Error("ParseJSONMap() = nil map on success, want non-nil")
112 }
113 })
114 }
115}

Callers

nothing calls this directly

Calls 4

ParseJSONMapFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected