forked from kiali/kiali
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps_test.go
55 lines (44 loc) · 1.18 KB
/
maps_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
package util
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRemoveNilValues(t *testing.T) {
vs := map[string]interface{}{
"k1": "v1",
"k2": nil,
"k3": map[string]interface{}{
"k3k1": "k3v1",
"k3k2": nil,
"k3k3": map[string]interface{}{
"k3k3k1": "k3k3v1",
"k3k3k2": nil,
"k3k3k3": "k3k3v3",
},
},
}
RemoveNilValues(vs)
_, k2 := vs["k2"]
_, k3k2 := (vs["k3"].(map[string]interface{}))["k3k2"]
_, k3k3k2 := ((vs["k3"].(map[string]interface{}))["k3k3"].(map[string]interface{}))["k3k3k2"]
assert.False(t, k2)
assert.False(t, k3k2)
assert.False(t, k3k3k2)
_, k1 := vs["k1"]
_, k3k1 := (vs["k3"].(map[string]interface{}))["k3k1"]
_, k3k3k1 := ((vs["k3"].(map[string]interface{}))["k3k3"].(map[string]interface{}))["k3k3k1"]
assert.True(t, k1)
assert.True(t, k3k1)
assert.True(t, k3k3k1)
}
func TestCopyMap(t *testing.T) {
initialMap := map[string]string{
"cluster": "east",
"namespace": "bookinfo",
}
copyMap := CopyStringMap(initialMap)
initialMap["cluster"] = "west"
assert.Equal(t, initialMap["cluster"], "west")
assert.Equal(t, copyMap["cluster"], "east")
assert.Equal(t, copyMap["namespace"], initialMap["namespace"])
}