-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflatten_test.go
92 lines (87 loc) · 2.2 KB
/
flatten_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
package kv
import (
"io"
"reflect"
"testing"
)
func TestFlatten(t *testing.T) {
tests := []struct {
v []interface{}
want []interface{}
}{
{
v: []interface{}{
"key1", "val1", "key2", 2,
},
want: []interface{}{
"key1", "val1", "key2", 2,
},
},
{
v: []interface{}{io.EOF},
want: []interface{}{"msg", io.EOF},
},
{
v: []interface{}{"msg", "the message", io.EOF},
want: []interface{}{"msg", "the message", "error", io.EOF},
},
{
v: []interface{}{"not found", "id", "A12345678"},
want: []interface{}{"msg", "not found", "id", "A12345678"},
},
{
v: []interface{}{"not_found", "id", "A12345678"},
want: []interface{}{"msg", "not_found", "id", "A12345678"},
},
{
v: []interface{}{1, 2, 3},
want: []interface{}{"_p1", 1, "_p2", 2, "_p3", 3},
},
{
v: []interface{}{1, 2, 3, 4},
want: []interface{}{"_p1", 1, "_p2", 2, "_p3", 3, "_p4", 4},
},
{
v: []interface{}{io.EOF, 2, 3, 4},
want: []interface{}{"msg", io.EOF, "_p1", 2, "_p2", 3, "_p3", 4},
},
{
v: []interface{}{"msg", "message 4", "key1", 1, 2},
want: []interface{}{"msg", "message 4", "key1", 1, "_p1", 2},
},
{
v: []interface{}{"msg", "server listening", "HTTP", "addr", ":6060"},
want: []interface{}{"msg", "server listening", "_p1", "HTTP", "addr", ":6060"},
},
{
v: []interface{}{"msg", "listening", "transport", "HTTP", ":6060"},
want: []interface{}{"msg", "listening", "transport", "HTTP", "_p1", ":6060"},
},
{
v: []interface{}{"msg", "level", "id"},
want: []interface{}{"_p1", "msg", "level", "id"},
},
{
v: []interface{}{"installing", "level", "id"},
want: []interface{}{"msg", "installing", "level", "id"},
},
{
v: []interface{}{List{"a", 1, "b", 2}},
want: []interface{}{"a", 1, "b", 2},
},
{
v: []interface{}{testKeyvalser{}, "5", 6},
want: []interface{}{"1", "2", "3", "4", "5", 6},
},
}
for i, tt := range tests {
got := flattenFix(tt.v)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("%d: want %v, got %v", i, tt.want, got)
}
}
}
type testKeyvalser struct{}
func (tkv testKeyvalser) Keyvals() []interface{} {
return []interface{}{"1", "2", "3", "4"}
}