-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
60 lines (54 loc) · 1.57 KB
/
main_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
package main
import "testing"
func TestRedisWorkersNotInKubernetes(t *testing.T) {
testCases := []struct {
kubernetesWorkers []string
redisWorkers []redisWorker
expectedResult []redisWorker
}{
// No dead redis workers should return an empty list
{
[]string{"vapor-worker-v1-abcd", "vapor-worker-v1-dcba"},
[]redisWorker{
{"vapor-worker-v1-abcd", "vapor-worker-v1-abcd:*"},
{"vapor-worker-v1-dcba", "vapor-worker-v1-dcba:*"},
},
[]redisWorker{},
},
// A dead worker should return a list that includes the dead worker
{
[]string{"vapor-worker-v1-abcd", "vapor-worker-v1-dcba"},
[]redisWorker{
{"vapor-worker-v1-abcd", "vapor-worker-v1-abcd:*"},
{"vapor-worker-v1-dcba", "vapor-worker-v1-dcba:*"},
{"vapor-worker-v1-abbb", "vapor-worker-v1-abbb:*"},
},
[]redisWorker{{"vapor-worker-v1-abbb", "vapor-worker-v1-abbb:*"}},
},
// A dead kubernetes worker should return an empty list
{
[]string{"vapor-worker-v1-abcd", "vapor-worker-v1-dcba"},
[]redisWorker{
{"vapor-worker-v1-abcd", "vapor-worker-v1-abcd:*"},
},
[]redisWorker{},
},
}
for _, testCase := range testCases {
deadRedisWorkers := redisWorkersNotInKubernetes(testCase.redisWorkers, testCase.kubernetesWorkers)
if !equal(deadRedisWorkers, testCase.expectedResult) {
t.Error("Expected", testCase.expectedResult, "got", deadRedisWorkers)
}
}
}
func equal(s1, s2 []redisWorker) bool {
if len(s1) != len(s2) {
return false
}
for i, s := range s1 {
if s2[i].name != s.name || s2[i].info != s.info {
return false
}
}
return true
}