-
Notifications
You must be signed in to change notification settings - Fork 4
/
map_test.go
57 lines (51 loc) · 1013 Bytes
/
map_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
package utils
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_LowerMapStringKey(t *testing.T) {
value := map[string]interface{}{
"storyID": "testing",
}
res := LowerMapStringKey(value)
assert.Equal(t, res["storyid"].(string), "testing")
}
func Test_MapValuesToOrderedSlice(t *testing.T) {
value := map[string]string{
"a": "A",
"b": "B",
"c": "C",
"d": "D",
"e": "E",
}
type tc struct {
order []string
output []string
}
testCases := []tc{
{
order: []string{"a", "b", "c"},
output: []string{"A", "B", "C"},
},
{
order: []string{"d", "e"},
output: []string{"D", "E"},
},
{
order: []string{"f", "g", "h"},
output: []string{"", "", ""},
},
{
order: []string{"c", "a", "d"},
output: []string{"C", "A", "D"},
},
{
order: []string{"d", "f", "a"},
output: []string{"D", "", "A"},
},
}
for _, tc := range testCases {
res := MapValuesToOrderedSlice(value, tc.order)
assert.EqualValues(t, tc.output, res)
}
}