-
Notifications
You must be signed in to change notification settings - Fork 15
/
reboot_test.go
77 lines (68 loc) · 1.87 KB
/
reboot_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
package cke
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestDedupRebootQueueEntries(t *testing.T) {
if DedupRebootQueueEntries(nil) != nil {
t.Errorf("DedupRebootQueueEntries(nil) must return nil")
}
e0 := &RebootQueueEntry{Node: "1.2.3.4"}
e1 := &RebootQueueEntry{Node: "5.6.7.8"}
e2 := &RebootQueueEntry{Node: "1.2.3.4"}
input := []*RebootQueueEntry{e0, e1, e2}
expected := []*RebootQueueEntry{e0, e1}
actual := DedupRebootQueueEntries(input)
// must be shallow comparison
if len(actual) != len(expected) || actual[0] != expected[0] || actual[1] != expected[1] {
t.Errorf("expected: %v, actual: %v", expected, actual)
}
}
func TestCountRebootQueueEntries(t *testing.T) {
input := []*RebootQueueEntry{
{Status: RebootStatusQueued},
{Status: RebootStatusDraining},
{Status: RebootStatusRebooting},
{Status: RebootStatusDraining},
{Status: RebootStatusRebooting},
{Status: RebootStatusRebooting},
}
expected := map[string]int{
"queued": 1,
"draining": 2,
"rebooting": 3,
"cancelled": 0,
}
actual := CountRebootQueueEntries(input)
if !cmp.Equal(actual, expected) {
t.Errorf("expected: %v, actual: %v", expected, actual)
}
}
func TestBuildNodeRebootStatus(t *testing.T) {
inputNodes := []*Node{
{Hostname: "node1", Address: "1.1.1.1"},
{Hostname: "node2", Address: "2.2.2.2"},
}
inputEntries := []*RebootQueueEntry{
{Node: "1.1.1.1", Status: RebootStatusRebooting},
{Node: "3.3.3.3", Status: RebootStatusCancelled},
}
expected := map[string]map[string]bool{
"node1": {
"queued": false,
"draining": false,
"rebooting": true,
"cancelled": false,
},
"node2": {
"queued": false,
"draining": false,
"rebooting": false,
"cancelled": false,
},
}
actual := BuildNodeRebootStatus(inputNodes, inputEntries)
if !cmp.Equal(actual, expected) {
t.Errorf("expected: %v, actual: %v", expected, actual)
}
}