MCPcopy Create free account
hub / github.com/algolia/cli / Test_JSONValue

Function Test_JSONValue

pkg/cmdutil/json_value_test.go:9–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func Test_JSONValue(t *testing.T) {
10 tests := []struct {
11 in string
12 types []string
13 out interface{}
14 err bool
15 }{
16 {
17 in: "string",
18 types: []string{
19 "string",
20 },
21 out: "string",
22 err: false,
23 },
24 {
25 in: "string",
26 types: []string{},
27 out: nil,
28 err: true,
29 },
30 {
31 in: `["array"]`,
32 types: []string{},
33 out: []interface{}{"array"},
34 err: false,
35 },
36 {
37 in: "true",
38 types: []string{},
39 out: true,
40 err: false,
41 },
42 }
43
44 for _, test := range tests {
45 j := NewJSONVar(test.types...)
46 err := j.Set(test.in)
47
48 if err != nil && !test.err {
49 t.Errorf("unexpected error: %v", err)
50 }
51 if err == nil && test.err {
52 t.Errorf("expected error, got none")
53 }
54
55 assert.Equal(t, test.out, j.Value)
56 }
57}

Callers

nothing calls this directly

Calls 3

NewJSONVarFunction · 0.85
ErrorfMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected