forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbios_test.go
254 lines (210 loc) · 7.23 KB
/
bios_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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var biosBody = `{
"@Redfish.Settings": {
"@odata.context": "/redfish/v1/$metadata#Settings.Settings",
"@odata.type": "#Settings.v1_2_1.Settings",
"SettingsObject": {
"@odata.id": "/redfish/v1/Systems/System.Embedded.1/Bios/Settings"
},
"SupportedApplyTimes": [
"OnReset",
"AtMaintenanceWindowStart",
"InMaintenanceWindowOnReset"
]
},
"@odata.type": "#Bios.v1_0_6.Bios",
"@odata.context": "/redfish/v1/$metadata#Bios.Bios",
"@odata.id": "/redfish/v1/Systems/437XR1138R2/BIOS",
"Id": "BIOS",
"Name": "BIOS Configuration Current Attributes",
"Description": "BIOS Attributes",
"AttributeRegistry": "BiosAttributeRegistryP89.v1_0_0",
"Attributes": {
"AdminPhone": "",
"BootMode": "Uefi",
"EmbeddedSata": "Raid",
"NicBoot1": "NetworkBoot",
"NicBoot2": "Disabled",
"PowerProfile": "MaxPerf",
"ProcCoreDisable": 3,
"ProcHyperthreading": "Enabled",
"ProcTurboMode": "Enabled",
"UsbControl": "UsbEnabled",
"BoolTest1": "True",
"BoolTest2": 1,
"BoolTest3": "NotBool"
},
"Actions": {
"#Bios.ResetBios": {
"target": "/redfish/v1/Systems/437XR1138R2/BIOS/Actions/Bios.ResetBios"
},
"#Bios.ChangePassword": {
"target": "/redfish/v1/Systems/437XR1138R2/BIOS/Actions/Bios.ChangePassword"
}
},
"Links": {
"ActiveSoftwareImage": {
"@odata.id": "/redfish/v1/Systems/437XR1138R2/BIOS/FirmwareInventory"
}
}
}`
var biosNoAttributesBody = `{
"@odata.type": "#Bios.v1_0_6.Bios",
"@odata.context": "/redfish/v1/$metadata#Bios.Bios",
"@odata.id": "/redfish/v1/Systems/437XR1138R2/BIOS",
"Id": "BIOS",
"Name": "BIOS Configuration Current Attributes",
"Description": "BIOS Attributes",
"AttributeRegistry": "BiosAttributeRegistryP89.v1_0_0",
"Attributes": {
"AdminPhone": "",
"BootMode": "Uefi",
"EmbeddedSata": "Raid",
"NicBoot1": "NetworkBoot",
"NicBoot2": "Disabled",
"PowerProfile": "MaxPerf",
"ProcCoreDisable": 3,
"ProcHyperthreading": "Enabled",
"ProcTurboMode": "Enabled",
"UsbControl": "UsbEnabled",
"BoolTest1": "True",
"BoolTest2": 1,
"BoolTest3": "NotBool"
},
"Actions": {
"#Bios.ResetBios": {
"target": "/redfish/v1/Systems/437XR1138R2/BIOS/Actions/Bios.ResetBios"
},
"#Bios.ChangePassword": {
"target": "/redfish/v1/Systems/437XR1138R2/BIOS/Actions/Bios.ChangePassword"
}
}
}`
// TestBios tests the parsing of Bios objects.
func TestBios(t *testing.T) {
var result Bios
err := json.NewDecoder(strings.NewReader(biosBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "BIOS" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "BIOS Configuration Current Attributes" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.AttributeRegistry != "BiosAttributeRegistryP89.v1_0_0" {
t.Errorf("Received incorrect attribute registry: %s", result.AttributeRegistry)
}
if result.resetBiosTarget != "/redfish/v1/Systems/437XR1138R2/BIOS/Actions/Bios.ResetBios" {
t.Errorf("Invalid ResetBios link: %s", result.resetBiosTarget)
}
if result.changePasswordTarget != "/redfish/v1/Systems/437XR1138R2/BIOS/Actions/Bios.ChangePassword" {
t.Errorf("Invalid ChangePassword target: %s", result.changePasswordTarget)
}
if result.Attributes.String("AdminPhone") != "" {
t.Errorf("Invalid 'AdminPhone' attribute: %s", result.Attributes["AdminPhone"])
}
if result.Attributes.String("PowerProfile") != "MaxPerf" {
t.Errorf("Invalid 'PowerProfile' attribute: %s", result.Attributes["PowerProfile"])
}
if result.Attributes.Int("ProcCoreDisable") != 3 {
t.Errorf("Invalid 'ProcCoreDisable' attribute: %v", result.Attributes["ProcCoreDisable"])
}
if !result.Attributes.Bool("BoolTest1") {
t.Errorf("Expected True boolean value for 'BoolTest1': %v", result.Attributes["BoolTest1"])
}
if !result.Attributes.Bool("BoolTest2") {
t.Errorf("Expected True boolean value for 'BoolTest2': %v", result.Attributes["BoolTest1"])
}
if result.Attributes.Bool("BoolTest3") {
t.Errorf("Expected False boolean value for 'BoolTest3': %v", result.Attributes["BoolTest1"])
}
if len(result.settingsApplyTimes) != 3 {
t.Errorf("Invalid settings support apply times: %s", result.settingsApplyTimes)
}
if result.activeSoftwareImage != "/redfish/v1/Systems/437XR1138R2/BIOS/FirmwareInventory" {
t.Errorf("Invalid value of activeSoftwareImage: '%s'", result.activeSoftwareImage)
}
}
// TestBiosAttributes tests the parsing of Bios objects @Redfish.Attributes.
func TestBiosAttributes(t *testing.T) {
var result Bios
err := json.NewDecoder(strings.NewReader(biosBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.settingsTarget != "/redfish/v1/Systems/System.Embedded.1/Bios/Settings" {
t.Errorf("Invalid settings update target: %s", result.settingsTarget)
}
}
// TestBiosNoAttributes tests the parsing of Bios objects without @Redfish.Attributes.
func TestBiosNoAttributes(t *testing.T) {
var result Bios
err := json.NewDecoder(strings.NewReader(biosNoAttributesBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.settingsTarget != "/redfish/v1/Systems/437XR1138R2/BIOS" {
t.Errorf("Invalid settings update target: %s", result.settingsTarget)
}
}
// TestUpdateBiosAttributes tests the UpdateBiosAttributes call.
func TestUpdateBiosAttributes(t *testing.T) {
var result Bios
err := json.NewDecoder(strings.NewReader(biosBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
update := SettingsAttributes{"AssetTag": "test"}
err = result.UpdateBiosAttributes(update)
if err != nil {
t.Errorf("Error making UpdateBiosAttributes call: %s", err)
}
calls := testClient.CapturedCalls()
if len(calls) != 2 {
t.Errorf("Expected one call to be made, captured: %v", calls)
}
if !strings.Contains(calls[1].Payload, "AssetTag") {
t.Errorf("Unexpected update payload: %s", calls[0].Payload)
}
if strings.Contains(calls[1].Payload, "@Redfish.SettingsApplyTime") {
t.Error("Expected 'SettingsApplyTime' to not be present")
}
}
// TestUpdateBiosAttributesApplyAt tests the TestUpdateBiosAttributesApplyAt call.
func TestUpdateBiosAttributesApplyAt(t *testing.T) {
var result Bios
err := json.NewDecoder(strings.NewReader(biosBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
update := SettingsAttributes{"AssetTag": "test"}
err = result.UpdateBiosAttributesApplyAt(update, common.AtMaintenanceWindowStartApplyTime)
if err != nil {
t.Errorf("Error making UpdateBiosAttributesApplyAt call: %s", err)
}
calls := testClient.CapturedCalls()
if len(calls) != 2 {
t.Errorf("Expected one call to be made, captured: %v", calls)
}
if !strings.Contains(calls[1].Payload, "AssetTag") {
t.Errorf("Unexpected update payload: %s", calls[0].Payload)
}
if !strings.Contains(calls[1].Payload, "@Redfish.SettingsApplyTime") {
t.Error("Expected 'SettingsApplyTime' to be present")
}
}