-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig_test.go
101 lines (97 loc) · 2.18 KB
/
config_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
package main
import (
"reflect"
"testing"
)
var configForTest = &Config{
Scopes: map[string]*Scope{
"": {
Values: []map[string]string{
{
"baz": "world!",
"foo": "Hello 1",
},
{
"baz": "world!",
"foo": "Hello 2",
},
},
},
"sample": {
Values: []map[string]string{
{
"foo": "Test1, world!",
"bar": "test1, test",
"baz": "baz",
},
{
"foo": "Test2, world!",
"bar": "test2, test",
},
{
"foo": "Test1, world!",
"bar": "test1, test",
"qux": "qux",
},
},
},
},
}
func Test_collectHistory(t *testing.T) {
testCases := []struct {
identifier *Identifier
expected []string
}{
{
identifier: &Identifier{key: "foo"},
expected: []string{"Hello 1", "Hello 2"},
},
{
identifier: &Identifier{key: "baz"},
expected: []string{"world!"},
},
{
&Identifier{scope: "sample", key: "foo"},
[]string{"Test1, world!", "Test2, world!"},
},
{
&Identifier{scope: "foo", key: "test"},
[]string{},
},
}
for _, tc := range testCases {
got := configForTest.collectHistory(tc.identifier)
if !reflect.DeepEqual(tc.expected, got) {
t.Errorf("collectHistory incorrect (expected: %+v, got: %+v)", tc.expected, got)
}
}
}
func Test_collectScopedPairHistory(t *testing.T) {
testCases := []struct {
identifier *IdentifierGroup
expected []string
}{
{
identifier: &IdentifierGroup{keys: []string{"foo", "baz"}},
expected: []string{"Hello 1, world!", "Hello 2, world!"},
},
{
identifier: &IdentifierGroup{scope: "sample", keys: []string{"foo", "bar"}},
expected: []string{"Test1,\\ world!, test1,\\ test", "Test2,\\ world!, test2,\\ test"},
},
{
identifier: &IdentifierGroup{scope: "sample", keys: []string{"foo", "bar", "baz"}},
expected: []string{"Test1,\\ world!, test1,\\ test, baz"},
},
{
identifier: &IdentifierGroup{scope: "foo", keys: []string{"test"}},
expected: []string{},
},
}
for _, tc := range testCases {
got := configForTest.collectScopedPairHistory(tc.identifier)
if !reflect.DeepEqual(tc.expected, got) {
t.Errorf("collectScopedPairHistory incorrect (expected: %+v, got: %+v)", tc.expected, got)
}
}
}