-
Notifications
You must be signed in to change notification settings - Fork 3
/
deinterfacer_test.go
108 lines (102 loc) · 1.93 KB
/
deinterfacer_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package junocfg
// https://golang.org/pkg/testing/
import (
"encoding/json"
"reflect"
//"bytes"
"testing"
)
var deinterfacerTests = []struct {
in map[string]interface{}
out map[string]interface{}
}{
{
in: map[string]interface{}{
"a": "a",
"b": []string{"b1", "b2", "b3", "b4"},
"c": map[interface{}]interface{}{
"ca": "ca",
"cb": []interface{}{
"cb1",
"cb2",
map[interface{}]interface{}{
"cb3a": "cb3aa",
},
"cb4",
map[string]interface{}{
"cb5a": "cb5aa",
},
},
},
"d": "a",
"e": map[string]interface{}{
"ea": "ea",
"eb": "eb",
"ec": "ec",
},
"f": []int{1, 2, 3, 4},
},
out: map[string]interface{}{
"a": "a",
"b": []interface{}{"b1", "b2", "b3", "b4"},
"c": map[string]interface{}{
"ca": "ca",
"cb": []interface{}{
"cb1",
"cb2",
map[string]interface{}{
"cb3a": "cb3aa",
},
"cb4",
map[string]interface{}{
"cb5a": "cb5aa",
},
},
},
"d": "a",
"e": map[string]interface{}{
"ea": "ea",
"eb": "eb",
"ec": "ec",
},
"f": []interface{}{1, 2, 3, 4},
},
},
{in: nil, out: map[string]interface{}{}},
{in: map[string]interface{}{}, out: map[string]interface{}{}},
{
in: map[string]interface{}{
"key_0": map[int]int{
1: 1,
2: 3,
5: 8,
13: 21,
},
},
out: map[string]interface{}{
"key_0": map[string]interface{}{
"1": 1,
"2": 3,
"5": 8,
"13": 21,
},
},
},
}
func Test_deinterfacer(t *testing.T) {
for i, tst := range deinterfacerTests {
out := deinterface(tst.in)
if !reflect.DeepEqual(tst.out, out) {
t.Errorf("For %d \nexpected %#v \ngot %#v", i, tst.out, out)
}
}
}
func Test_deinterfacereMarshallable(t *testing.T) {
for i, tst := range deinterfacerTests {
out := deinterface(tst.in)
_, err := json.Marshal(out)
if err != nil {
t.Errorf("For %d got error while marshalling %s", i, err)
}
}
}