(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func 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 | } |
nothing calls this directly
no test coverage detected