forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowersubsystem_test.go
129 lines (120 loc) · 3.47 KB
/
powersubsystem_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"fmt"
"strings"
"testing"
)
var powerSubsystemBody = `{
"@odata.type": "#PowerSubsystem.v1_1_1.PowerSubsystem",
"Id": "PowerSubsystem",
"Name": "Power Subsystem for Chassis",
"CapacityWatts": 2000,
"Allocation": {
"RequestedWatts": 1500,
"AllocatedWatts": 1200
},
"PowerSupplyRedundancy": [
{
"RedundancyType": "Failover",
"MaxSupportedInGroup": 2,
"MinNeededInGroup": 1,
"RedundancyGroup": [
{
"@odata.id": "/redfish/v1/Chassis/1U/PowerSubsystem/PowerSupplies/Bay1"
},
{
"@odata.id": "/redfish/v1/Chassis/1U/PowerSubsystem/PowerSupplies/Bay2"
}
],
"Status": {
"State": "UnavailableOffline",
"Health": "OK"
}
}
],
"PowerSupplies": {
"@odata.id": "/redfish/v1/Chassis/1U/PowerSubsystem/PowerSupplies"
},
"Status": {
"State": "Enabled",
"Health": "OK"
},
"@odata.id": "/redfish/v1/Chassis/1U/PowerSubsystem"
}`
var powerSubsystemNVBody = `{
"@odata.context": "/redfish/v1/$metadata#PowerSubsystem.PowerSubsystem",
"@odata.etag": "\"1715094363\"",
"@odata.id": "/redfish/v1/Chassis/DGX/PowerSubsystem",
"@odata.type": "#PowerSubsystem.v1_1_0.PowerSubsystem",
"Allocation": [],
"Description": "PowerSubsytem for this Chassis",
"Id": "PowerSubsytem",
"Name": "PowerSubsytem",
"PowerSupplies": {
"@odata.id": "/redfish/v1/Chassis/DGX/PowerSubsystem/PowerSupplies"
},
"PowerSupplyRedundancy": [
{
"MaxSupportedInGroup": 6,
"MinNeededInGroup": 1,
"RedundancyGroup": [
{
"@odata.id": "/redfish/v1/Chassis/DGX/PowerSubsystem/PowerSupplies/PSU0"
},
{
"@odata.id": "/redfish/v1/Chassis/DGX/PowerSubsystem/PowerSupplies/PSU1"
},
{
"@odata.id": "/redfish/v1/Chassis/DGX/PowerSubsystem/PowerSupplies/PSU2"
},
{
"@odata.id": "/redfish/v1/Chassis/DGX/PowerSubsystem/PowerSupplies/PSU3"
},
{
"@odata.id": "/redfish/v1/Chassis/DGX/PowerSubsystem/PowerSupplies/PSU4"
},
{
"@odata.id": "/redfish/v1/Chassis/DGX/PowerSubsystem/PowerSupplies/PSU5"
}
],
"[email protected]": 6,
"RedundancyType": "NPlusM",
"Status": {
"Health": "OK",
"State": "Enabled"
}
}
],
"Status": {
"Health": "OK",
"State": "Enabled"
}
}`
// TestPowerSubsystem tests the parsing of PowerSubsystem objects.
func TestPowerSubsystem(t *testing.T) {
var result PowerSubsystem
err := json.NewDecoder(strings.NewReader(powerSubsystemBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertEquals(t, "PowerSubsystem", result.ID)
assertEquals(t, "Power Subsystem for Chassis", result.Name)
assertEquals(t, "2000", fmt.Sprintf("%.0f", result.CapacityWatts))
assertEquals(t, "1500", fmt.Sprintf("%.0f", result.Allocation.RequestedWatts))
assertEquals(t, "1200", fmt.Sprintf("%.0f", result.Allocation.AllocatedWatts))
assertEquals(t, "Failover", string(result.PowerSupplyRedundancy[0].RedundancyType))
assertEquals(t, "/redfish/v1/Chassis/1U/PowerSubsystem/PowerSupplies/Bay2", result.PowerSupplyRedundancy[0].redundancyGroup[1])
assertEquals(t, "/redfish/v1/Chassis/1U/PowerSubsystem/PowerSupplies", result.powerSupplies)
}
// TestPowerSubsystemNVWorkaround tests the workaround for a non-spec implementation of PowerSubsystem objects.
func TestPowerSubsystemNVWorkaround(t *testing.T) {
var result PowerSubsystem
err := json.NewDecoder(strings.NewReader(powerSubsystemNVBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
}