-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseverity_test.go
More file actions
80 lines (71 loc) · 1.81 KB
/
Copy pathseverity_test.go
File metadata and controls
80 lines (71 loc) · 1.81 KB
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
package repomap
import "testing"
func TestSeverityValue(t *testing.T) {
tests := []struct {
severity Severity
expected int
}{
{Critical, 5},
{High, 4},
{Medium, 3},
{Low, 2},
{Info, 1},
{Severity("unknown"), 0},
}
for _, tt := range tests {
if got := tt.severity.Value(); got != tt.expected {
t.Errorf("Severity(%q).Value() = %d, want %d", tt.severity, got, tt.expected)
}
}
}
func TestParseSeverity(t *testing.T) {
tests := []struct {
input string
expected Severity
}{
{"critical", Critical},
{"CRITICAL", Critical},
{"High", High},
{"medium", Medium},
{"low", Low},
{"info", Info},
{"garbage", Medium},
}
for _, tt := range tests {
if got := ParseSeverity(tt.input); got != tt.expected {
t.Errorf("ParseSeverity(%q) = %q, want %q", tt.input, got, tt.expected)
}
}
}
func TestMaxSeverity(t *testing.T) {
if got := MaxSeverity(High, Low); got != High {
t.Errorf("MaxSeverity(High, Low) = %q, want High", got)
}
if got := MaxSeverity(Info, Critical); got != Critical {
t.Errorf("MaxSeverity(Info, Critical) = %q, want Critical", got)
}
}
func TestMaxSeverities(t *testing.T) {
if got := MaxSeverities([]Severity{Low, High, Medium}); got != High {
t.Errorf("MaxSeverities([Low, High, Medium]) = %q, want High", got)
}
if got := MaxSeverities(nil); got != Medium {
t.Errorf("MaxSeverities(nil) = %q, want Medium", got)
}
}
func TestSeverityDistribution(t *testing.T) {
sd := &SeverityDistribution{}
sd.Add(Critical)
sd.Add(High)
sd.Add(High)
sd.Add(Low)
if sd.Total() != 4 {
t.Errorf("Total() = %d, want 4", sd.Total())
}
if sd.Max() != Critical {
t.Errorf("Max() = %q, want Critical", sd.Max())
}
if sd.Critical != 1 || sd.High != 2 || sd.Low != 1 {
t.Errorf("Distribution = {C:%d H:%d L:%d}, want {C:1 H:2 L:1}", sd.Critical, sd.High, sd.Low)
}
}