-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprint_response_test.go
84 lines (77 loc) · 1.65 KB
/
print_response_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
// Test cases struct
type testCase struct {
input map[string]any
expected map[string]any
}
func TestParseInnerJSON(t *testing.T) {
t.Parallel()
tests := map[string]testCase{
"nested JSON string": {
input: map[string]any{
"key1": `{"nestedKey1": "value1", "nestedKey2": 2}`,
"key2": "plain string",
},
expected: map[string]any{
"key1": map[string]any{
"nestedKey1": "value1",
"nestedKey2": 2.0,
},
"key2": "plain string",
},
},
"invalid JSON string": {
input: map[string]any{
"key1": `{"nestedKey1": "value1", "nestedKey2": 2`,
"key2": "plain string",
},
expected: map[string]any{
"key1": `{"nestedKey1": "value1", "nestedKey2": 2`,
"key2": "plain string",
},
},
"non-string value": {
input: map[string]any{
"key1": 123,
"key2": "plain string",
},
expected: map[string]any{
"key1": 123,
"key2": "plain string",
},
},
"array inside a string": {
input: map[string]any{
"key1": `["value1", "value2", "value3"]`,
"key2": "plain string",
},
expected: map[string]any{
"key1": []any{"value1", "value2", "value3"},
"key2": "plain string",
},
},
"array as a value that's a string": {
input: map[string]any{
"key1": "[1, 2, 3]",
"key2": `["a", "b", "c"]`,
},
expected: map[string]any{
"key1": []any{1.0, 2.0, 3.0},
"key2": []any{"a", "b", "c"},
},
},
}
for name, tc := range tests {
t.Run(
name, func(t *testing.T) {
t.Parallel()
actual := parseInnerJSON(tc.input)
assert.Equal(t, tc.expected, actual)
},
)
}
}