forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpciedevice_test.go
187 lines (161 loc) · 4.32 KB
/
pciedevice_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var (
pcieDeviceBody = `{
"@odata.context": "/redfish/v1/$metadata#PCIeDevice.PCIeDevice",
"@odata.type": "#PCIeDevice.v1_3_1.PCIeDevice",
"@odata.id": "/redfish/v1/PCIeDevice",
"Id": "PCIeDevice-1",
"Name": "PCIeDeviceOne",
"Description": "PCIeDevice One",
"Assembly": {
"@odata.id": "/redfish/v1/Assembly/1"
},
"AssetTag": "Tag-1",
"DeviceType": "Simulated",
"FirmwareVersion": "1.2",
"Links": {
"Chassis": [{
"@odata.id": "/redfish/v1/Chassis/Chassis-1"
}],
"[email protected]": 1
},
"Manufacturer": "Acme Inc",
"Model": "A1",
"PCIeFunctions": {
"@odata.id": "/redfish/v1/Systems/system/PCIeDevices/AAABBCC/PCIeFunctions"
},
"PCIeInterface": {
"LanesInUse": 32,
"MaxLanes": 32,
"MaxPCIeType": "Gen4",
"PCIeType": "Gen4"
},
"PartNumber": "1234",
"SKU": "4321",
"SerialNumber": "A1111",
"Status": {
"State": "Enabled",
"Health": "OK"
}
}`
pcieDeviceOldBody = `{
"@odata.context": "/redfish/v1/$metadata#PCIeDevice.PCIeDevice",
"@odata.type": "#PCIeDevice.v1_3_1.PCIeDevice",
"@odata.id": "/redfish/v1/PCIeDevice",
"Id": "PCIeDevice-1",
"Name": "PCIeDeviceOne",
"Description": "PCIeDevice One",
"Assembly": {
"@odata.id": "/redfish/v1/Assembly/1"
},
"AssetTag": "Tag-1",
"DeviceType": "Simulated",
"FirmwareVersion": "1.2",
"Links": {
"Chassis": [{
"@odata.id": "/redfish/v1/Chassis/Chassis-1"
}],
"[email protected]": 1,
"PCIeFunctions": [{
"@odata.id": "/redfish/v1/Functions/1"
},
{
"@odata.id": "/redfish/v1/Functions/2"
}
],
"[email protected]": 2
},
"Manufacturer": "Acme Inc",
"Model": "A1",
"PCIeInterface": {
"LanesInUse": 32,
"MaxLanes": 32,
"MaxPCIeType": "Gen4",
"PCIeType": "Gen4"
},
"PartNumber": "1234",
"SKU": "4321",
"SerialNumber": "A1111",
"Status": {
"State": "Enabled",
"Health": "OK"
}
}`
)
// TestPCIeDevice tests the parsing of PCIeDevice objects.
func TestPCIeDevice(t *testing.T) {
var result PCIeDevice
err := json.NewDecoder(strings.NewReader(pcieDeviceBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "PCIeDevice-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "PCIeDeviceOne" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.DeviceType != SimulatedDeviceType {
t.Errorf("Invalid device type: %s", result.DeviceType)
}
if result.PCIeInterface.MaxLanes != 32 {
t.Errorf("Invalid max lanes: %d", result.PCIeInterface.MaxLanes)
}
if result.PCIeInterface.PCIeType != Gen4PCIeTypes {
t.Errorf("Invalid PCIe type: %s", result.PCIeInterface.PCIeType)
}
}
// TestDeprecatedPCIeDevice tests the parsing of deprecated PCIeDevice objects.
func TestOldPCIeDevice(t *testing.T) {
var result PCIeDevice
err := json.NewDecoder(strings.NewReader(pcieDeviceOldBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "PCIeDevice-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "PCIeDeviceOne" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.DeviceType != SimulatedDeviceType {
t.Errorf("Invalid device type: %s", result.DeviceType)
}
if result.PCIeInterface.MaxLanes != 32 {
t.Errorf("Invalid max lanes: %d", result.PCIeInterface.MaxLanes)
}
if result.PCIeInterface.PCIeType != Gen4PCIeTypes {
t.Errorf("Invalid PCIe type: %s", result.PCIeInterface.PCIeType)
}
if len(result.pcieFunctionsArray) != 2 {
t.Errorf("Invalid PCIeFunctions count: %v", len(result.pcieFunctionsArray))
}
}
// TestPCIeDeviceUpdate tests the Update call.
func TestPCIeDeviceUpdate(t *testing.T) {
var result PCIeDevice
err := json.NewDecoder(strings.NewReader(pcieDeviceBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
result.AssetTag = TestAssetTag
err = result.Update()
if err != nil {
t.Errorf("Error making Update call: %s", err)
}
calls := testClient.CapturedCalls()
if !strings.Contains(calls[0].Payload, "AssetTag:TestAssetTag") {
t.Errorf("Unexpected AssetTag update payload: %s", calls[0].Payload)
}
}