-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_test.go
125 lines (97 loc) · 2.71 KB
/
node_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"testing"
)
const (
nodeName = "node"
labelName = "label"
)
func TestNodeLabelMap_ResetLabels(t *testing.T) {
nodeLabelMap := NewNodeLabelMap()
nodeLabelMap.Add(nodeName)
nodeLabelMap.AddLabelToNode(nodeName, labelName)
nodeLabelMap.ResetLabels(nodeName)
if nodeLabelMap.m[nodeName][labelName] != false {
t.Error("unexpected label state in node label map, expected false")
}
}
func TestNodeLabelMap_Add(t *testing.T) {
nodeLabelMap := NewNodeLabelMap()
nodeLabelMap.Add(nodeName)
if _, exists := nodeLabelMap.m[nodeName]; !exists {
t.Error("node not found in node label map")
}
}
func TestNodeLabelMap_Remove(t *testing.T) {
nodeLabelMap := NewNodeLabelMap()
nodeLabelMap.Add(nodeName)
nodeLabelMap.Remove(nodeName)
if _, exists := nodeLabelMap.m[nodeName]; exists {
t.Error("node unexpectedly found in node label map")
}
}
func TestNodeLabelMap_AddLabelToNode(t *testing.T) {
nodeLabelMap := NewNodeLabelMap()
nodeLabelMap.Add(nodeName)
nodeLabelMap.AddLabelToNode(nodeName, labelName)
if nodeLabelMap.m[nodeName][labelName] != true {
t.Error("unexpected label state in node label map, expected true")
}
}
func TestNodeLabelMap_RemoveLabelFromNode(t *testing.T) {
nodeLabelMap := NewNodeLabelMap()
nodeLabelMap.Add(nodeName)
nodeLabelMap.AddLabelToNode(nodeName, labelName)
nodeLabelMap.RemoveLabelFromNode(nodeName, labelName)
if _, exists := nodeLabelMap.m[nodeName][labelName]; exists {
t.Error("node label unexpectedly found in node label map")
}
}
func TestNodeLabelMap_GetLabels(t *testing.T) {
nodeLabelMap := NewNodeLabelMap()
nodeLabelMap.Add(nodeName)
nodeLabelMap.AddLabelToNode(nodeName, labelName)
matched := false
labels := nodeLabelMap.GetLabels(nodeName)
if len(labels) != 1 {
t.Error("unexpected node label count")
}
for label := range labels {
if label == labelName {
matched = true
break
}
}
if !matched {
t.Error("unexpected node label result")
}
}
func TestNodeLabelMap_SetPossible(t *testing.T) {
nodeLabelMap := NewNodeLabelMap()
nodeLabelMap.Add(nodeName)
possibleLabelMap = make(map[string][]string, 0)
possibleLabelMap[labelName] = []string{labelName}
nodeLabels := make(map[string]string, 0)
nodeLabels[labelName] = "true"
nodeLabelMap.SetPossible(nodeName, nodeLabels)
labels := nodeLabelMap.GetLabels(nodeName)
if len(labels) != 1 {
t.Error("unexpected node label count")
}
matched := false
for label := range labels {
if label == labelName {
matched = true
break
}
}
if !matched {
t.Error("unexpected node label result")
}
}
func TestNodeLabelMap_Valid(t *testing.T) {
nodeLabelMap := NewNodeLabelMap()
if nodeLabelMap.Valid(nodeName) != false {
t.Error("unexpected node validity state")
}
}