forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhostinterface_test.go
134 lines (113 loc) · 3.28 KB
/
hostinterface_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var hostInterfaceBody = `{
"@odata.context": "/redfish/v1/$metadata#HostInterface.HostInterface",
"@odata.type": "#HostInterface.v1_0_0.HostInterface",
"@odata.id": "/redfish/v1/HostInterface",
"Id": "HostInterface-1",
"Name": "HostInterfaceOne",
"Description": "HostInterface One",
"AuthNoneRoleId": "role-1",
"AuthenticationModes": [
"BasicAuth",
"RedfishSessionAuth"
],
"ExternallyAccessible": true,
"FirmwareAuthEnabled": false,
"FirmwareAuthRoleId": "role-1",
"HostEthernetInterfaces": {
"@odata.id": "/redfish/v1/Host/1/EthernetInterfaceCollection"
},
"HostInterfaceType": "NetworkHostInterface",
"InterfaceEnabled": true,
"KernelAuthEnabled": false,
"KernelAuthRoleId": "role-2",
"Links": {
"AuthNoneRole": {
"@odata.id": "/redfish/v1/Roles/role-1"
},
"ComputerSystems": [{
"@odata.id": "/redfish/v1/Systems/System-1"
}
],
"[email protected]": 1,
"FirmwareAuthRole": {
"@odata.id": "/redfish/v1/Roles/role-1"
},
"KernelAuthRole": {
"@odata.id": "/redfish/v1/Roles/role-2"
}
},
"ManagerEthernetInterface": {
"@odata.id": "/redfish/v1/Host/1/EthernetInterface/1"
},
"NetworkProtocol": {
"@odata.id": "/redfish/v1/Host/1/ManagerNetworkProtocol/1"
},
"Status": {
"State": "Enabled",
"Health": "OK"
}
}`
// TestHostInterface tests the parsing of HostInterface objects.
func TestHostInterface(t *testing.T) {
var result HostInterface
err := json.NewDecoder(strings.NewReader(hostInterfaceBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "HostInterface-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "HostInterfaceOne" {
t.Errorf("Received invalid name: %s", result.Name)
}
if len(result.AuthenticationModes) != 2 {
t.Errorf("Expected 2 auth modes, got: %d", len(result.AuthenticationModes))
}
if !result.ExternallyAccessible {
t.Error("Should be externally accessible")
}
if result.FirmwareAuthEnabled {
t.Error("Firmware auth should not be enabled")
}
if result.authNoneRole != "/redfish/v1/Roles/role-1" {
t.Errorf("Received incorrect auth role none link: %s", result.authNoneRole)
}
if len(result.computerSystems) != 1 {
t.Errorf("Should be 1 computer system, got %d", len(result.computerSystems))
}
}
// TestHostInterfaceUpdate tests the Update call.
func TestHostInterfaceUpdate(t *testing.T) {
var result HostInterface
err := json.NewDecoder(strings.NewReader(hostInterfaceBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
// TODO: Need to handle converted names
// result.AuthNoneRoleID = "role-test"
// result.FirmwareAuthRoleID = "role-1"
result.InterfaceEnabled = false
err = result.Update()
if err != nil {
t.Errorf("Error making Update call: %s", err)
}
calls := testClient.CapturedCalls()
if len(calls) != 1 {
t.Errorf("Expected 1 API call, found %d", len(calls))
}
if !strings.Contains(calls[0].Payload, "InterfaceEnabled") {
t.Errorf("Unexpected InterfaceEnabled update payload: %s", calls[0].Payload)
}
}