-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirmware_test.go
More file actions
136 lines (120 loc) · 3.26 KB
/
firmware_test.go
File metadata and controls
136 lines (120 loc) · 3.26 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
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
126
127
128
129
130
131
132
133
134
135
136
package ilo
import (
"strings"
"testing"
"github.com/NETWAYS/check_hp_firmware/snmp"
"github.com/NETWAYS/go-check"
)
func TestIlo_GetNagiosStatus(t *testing.T) {
testcases := map[string]struct {
ilo Ilo
expectedState int
expectedOutput string
}{
"too-old": {
ilo: Ilo{
Model: "pciIntegratedLightsOutRemoteInsight3",
ModelID: 9,
RomRevision: "1.40",
},
expectedState: check.Warning,
expectedOutput: "Patch available",
},
"newer": {
ilo: Ilo{
Model: "pciIntegratedLightsOutRemoteInsight3",
ModelID: 9,
RomRevision: "2.18",
},
expectedState: check.OK,
expectedOutput: "2.18 - version newer than affected",
},
"pretty-old": {
ilo: Ilo{
Model: "pciIntegratedLightsOutRemoteInsight2",
ModelID: 7,
RomRevision: "2.18",
},
expectedState: check.Critical,
expectedOutput: "is pretty old and likely unsafe",
},
"unknown-new": {
ilo: Ilo{
Model: "verynew",
ModelID: 12,
RomRevision: "2.18",
},
expectedState: check.OK,
expectedOutput: "verynew (12) revision 2.18 not known for any issues",
},
}
for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
state, output := tc.ilo.GetNagiosStatus(1)
if state != tc.expectedState {
t.Fatalf("expected %v, got %v", tc.expectedState, state)
}
if !strings.Contains(output, tc.expectedOutput) {
t.Fatalf("expected %v, got %v", tc.expectedOutput, output)
}
})
}
}
func TestIsNewerVersion(t *testing.T) {
tests := []struct {
current string
required string
expected bool
}{
{"1.0", "1.0", true},
{"1.0", "1.1", true},
{"1.0", "5", true},
{"1.0", "10.1.0", true},
{"1.0", "0.9", false},
{"1.0", "0.9", false}, // Duplicate test case (can be removed if not intentional)
{"1.0", "0.0", false},
{"1.0", "0", false},
{"1.0", "foobar", false},
{"foobar", "1.0", false},
{"xxx", "xxx", false},
}
for _, test := range tests {
result := isNewerVersion(test.current, test.required)
if result != test.expected {
t.Errorf("isNewerVersion(%q, %q) = %v, want %v",
test.current, test.required, result, test.expected)
}
}
}
func TestGetIloInformation_ilo5(t *testing.T) {
c, _ := snmp.NewFileHandlerFromFile("../../testdata/ilo5.txt")
i, err := GetIloInformation(c)
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
if i.ModelID != 11 {
t.Errorf("Expected ModelID to be %d, got %d", 11, i.ModelID)
}
if i.Model != "pciIntegratedLightsOutRemoteInsight5" {
t.Errorf("Expected Model to be %q, got %q", "pciIntegratedLightsOutRemoteInsight5", i.Model)
}
if i.RomRevision != "3.00" {
t.Errorf("Expected RomRevision to be %q, got %q", "3.00", i.RomRevision)
}
}
func TestGetIloInformation_ilo6(t *testing.T) {
c, _ := snmp.NewFileHandlerFromFile("../../testdata/ilo6.txt")
i, err := GetIloInformation(c)
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
if i.ModelID != 12 {
t.Errorf("Expected ModelID to be %d, got %d", 12, i.ModelID)
}
if i.Model != "pciIntegratedLightsOutRemoteInsight6" {
t.Errorf("Expected Model to be %q, got %q", "pciIntegratedLightsOutRemoteInsight6", i.Model)
}
if i.RomRevision != "1.55" {
t.Errorf("Expected RomRevision to be %q, got %q", "1.55", i.RomRevision)
}
}