-
Notifications
You must be signed in to change notification settings - Fork 12
/
labels_test.go
91 lines (83 loc) · 1.96 KB
/
labels_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
package fiber_test
import (
"sort"
"testing"
"github.com/gojek/fiber"
"github.com/stretchr/testify/assert"
)
func TestLabelsMapKeys(t *testing.T) {
tests := map[string]struct {
data fiber.LabelsMap
expected []string
}{
"empty map": {
data: fiber.LabelsMap{},
expected: []string{},
},
"non-empty map": {
data: fiber.LabelsMap{"k1": []string{"v1", "v2"}, "k2": []string{"v3"}},
expected: []string{"k1", "k2"},
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
keys := tt.data.Keys()
// Sort and compare
sort.Slice(keys, func(p, q int) bool {
return keys[p] < keys[q]
})
assert.Equal(t, tt.expected, keys)
})
}
}
func TestLabelsMapWithLabel(t *testing.T) {
tests := map[string]struct {
data fiber.LabelsMap
key string
values []string
expected fiber.LabelsMap
}{
"set key": {
data: fiber.LabelsMap{},
key: "k1",
values: []string{"v1", "v2"},
expected: fiber.LabelsMap{"k1": []string{"v1", "v2"}},
},
"overwrite key": {
data: fiber.LabelsMap{"k1": []string{"v1", "v2"}, "k2": []string{"v3"}},
key: "k2",
values: []string{"new-val"},
expected: fiber.LabelsMap{"k1": []string{"v1", "v2"}, "k2": []string{"new-val"}},
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
newMap := tt.data.WithLabel(tt.key, tt.values...)
assert.Equal(t, tt.expected, newMap)
})
}
}
func TestLabelsMapLabel(t *testing.T) {
tests := map[string]struct {
data fiber.LabelsMap
key string
expected []string
}{
"empty map": {
data: fiber.LabelsMap{},
key: "k",
expected: []string{},
},
"non-empty map": {
data: fiber.LabelsMap{"k1": []string{"v1", "v2"}, "k2": []string{"v3"}},
key: "k1",
expected: []string{"v1", "v2"},
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
values := tt.data.Label(tt.key)
assert.Equal(t, tt.expected, values)
})
}
}