-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectevent_test.go
54 lines (49 loc) · 1.7 KB
/
selectevent_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
package main
import (
"testing"
)
func TestSelectEvent(t *testing.T) {
var tests = []struct {
description string
state State
eventType string
involvedObject string
reason string
expected bool
}{
{"match_type", getState("Warning", "", ""), "Warning", "", "", true},
{"match_involved_object", getState("", "Pod", ""), "", "Pod", "", true},
{"match_reason", getState("", "", "Failed"), "", "", "Failed", true},
{"mismatch_type", getState("Warning", "", ""), "Normal", "", "", false},
{"mismatch_involved_object", getState("Warning", "ConfigMap", ""), "Warning", "", "", false},
{"mismatch_reason", getState("Warning", "", "Completed"), "Warning", "", "Failed,Evicted,FailedMount", false},
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
result := selectEvent(test.state, test.eventType, test.involvedObject, test.reason)
if result != test.expected {
t.Errorf("Expected result %t for parameters state=%v, eventType=%s, involvedObject=%s, reason=%s", result, test.state, test.eventType, test.involvedObject, test.reason)
}
})
}
}
func TestSelectGeneric(t *testing.T) {
var tests = []struct {
description string
items []string
item string
expected bool
}{
{"empty_list", []string{}, "Warning", true},
{"match", []string{"Normal", "Warning"}, "Warning", true},
{"mismatch", []string{"Failed", "Evicted"}, "FailedScheduling", false},
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
result := selectGeneric(test.items, test.item)
if result != test.expected {
t.Errorf("Expected result %t for parameters items=%v, item=%s", result, test.items, test.item)
}
})
}
}