forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecureboot_test.go
90 lines (71 loc) · 2.19 KB
/
secureboot_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var secureBootBody = `{
"@odata.context": "/redfish/v1/$metadata#SecureBoot.SecureBoot",
"@odata.type": "#SecureBoot.v1_0_5.SecureBoot",
"@odata.id": "/redfish/v1/SecureBoot",
"Id": "SecureBoot-1",
"Name": "SecureBootOne",
"Description": "SecureBoot One",
"SecureBootCurrentBoot": "Enabled",
"SecureBootEnable": true,
"SecureBootMode": "UserMode",
"Actions": {
"#SecureBoot.ResetKeys": {
"target": "/redfish/v1/SecureBoot/Actions/SecureBoot.ResetKeys"
}
}
}`
// TestSecureBoot tests the parsing of SecureBoot objects.
func TestSecureBoot(t *testing.T) {
var result SecureBoot
err := json.NewDecoder(strings.NewReader(secureBootBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "SecureBoot-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "SecureBootOne" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.SecureBootCurrentBoot != EnabledSecureBootCurrentBootType {
t.Errorf("Invalid SecureBootCurrentBoot: %s", result.SecureBootCurrentBoot)
}
if !result.SecureBootEnable {
t.Error("SecureBootEnable should be true")
}
if result.SecureBootMode != UserModeSecureBootModeType {
t.Errorf("Invalid SecureBootMode: %s", result.SecureBootMode)
}
if result.resetKeysTarget != "/redfish/v1/SecureBoot/Actions/SecureBoot.ResetKeys" {
t.Errorf("Invalid ResetKeys target: %s", result.resetKeysTarget)
}
}
// TestSecureBootUpdate tests the Update call.
func TestSecureBootUpdate(t *testing.T) {
var result SecureBoot
err := json.NewDecoder(strings.NewReader(secureBootBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
result.SecureBootEnable = false
err = result.Update()
if err != nil {
t.Errorf("Error making Update call: %s", err)
}
calls := testClient.CapturedCalls()
if !strings.Contains(calls[0].Payload, "SecureBootEnable:false") {
t.Errorf("Unexpected SecureBootEnable update payload: %s", calls[0].Payload)
}
}