forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutletgroup_test.go
156 lines (129 loc) · 4.23 KB
/
outletgroup_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var outletGroupBody = `{
"@odata.type": "#OutletGroup.v1_1_2.OutletGroup",
"Id": "Rack5Storage",
"Name": "Outlet Group Rack5Storage",
"Status": {
"Health": "OK",
"State": "Enabled"
},
"CreatedBy": "Bob",
"PowerOnDelaySeconds": 4,
"PowerOffDelaySeconds": 0,
"PowerState": "On",
"PowerEnabled": true,
"PowerWatts": {
"DataSourceUri": "/redfish/v1/PowerEquipment/RackPDUs/1/Sensors/GroupPowerA",
"Reading": 412.36
},
"EnergykWh": {
"DataSourceUri": "/redfish/v1/PowerEquipment/RackPDUs/1/Sensors/GroupEnergyA",
"Reading": 26880
},
"Links": {
"Outlets": [
{
"@odata.id": "/redfish/v1/PowerEquipment/RackPDUs/1/Outlets/A1"
},
{
"@odata.id": "/redfish/v1/PowerEquipment/RackPDUs/1/Outlets/A2"
},
{
"@odata.id": "/redfish/v1/PowerEquipment/RackPDUs/1/Outlets/A3"
}
]
},
"Actions": {
"#OutletGroup.PowerControl": {
"target": "/redfish/v1/PowerEquipment/RackPDUs/1/OutletGroups/Rack5Storage/OutletGroup.PowerControl"
},
"#OutletGroup.ResetMetrics": {
"target": "/redfish/v1/PowerEquipment/RackPDUs/1/OutletGroups/Rack5Storage/OutletGroup.ResetMetrics"
}
},
"@odata.id": "/redfish/v1/PowerEquipment/RackPDUs/1/OutletGroups/Rack5Storage"
}`
// TestOutletGroup tests the parsing of OutletGroup objects.
func TestOutletGroup(t *testing.T) {
var result OutletGroup
err := json.NewDecoder(strings.NewReader(outletGroupBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertEquals(t, "Rack5Storage", result.ID)
assertEquals(t, "Outlet Group Rack5Storage", result.Name)
assertEquals(t, "Bob", result.CreatedBy)
assertEquals(t, "On", string(result.PowerState))
assertEquals(t, "/redfish/v1/PowerEquipment/RackPDUs/1/Sensors/GroupPowerA", result.PowerWatts.DataSourceURI)
assertEquals(t, "/redfish/v1/PowerEquipment/RackPDUs/1/Sensors/GroupEnergyA", result.EnergykWh.DataSourceURI)
assertEquals(t, "/redfish/v1/PowerEquipment/RackPDUs/1/Outlets/A1", result.outlets[0])
if !result.PowerEnabled {
t.Error("Expected power to be enabled")
}
if result.PowerOnDelaySeconds != 4 {
t.Errorf("Unexpected PowerOnDelaySeconds value: %.2f", result.PowerOnDelaySeconds)
}
if result.PowerOffDelaySeconds != 0 {
t.Errorf("Unexpected PowerOffDelaySeconds value: %.2f", result.PowerOffDelaySeconds)
}
if result.PowerWatts.Reading != 412.36 {
t.Errorf("Unexpected PowerWatts.Reading value: %.2f", result.PowerWatts.Reading)
}
}
// TestOutletGroupResetMetrics tests the OutletGroup ResetMetrics call.
func TestOutletGroupResetMetrics(t *testing.T) {
var result OutletGroup
err := json.NewDecoder(strings.NewReader(outletGroupBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
err = result.ResetMetrics()
if err != nil {
t.Errorf("Error making ResetMetrics call: %s", err)
}
calls := testClient.CapturedCalls()
if len(calls) != 1 {
t.Errorf("Expected one call to be made, captured: %#v", calls)
}
if calls[0].Payload != "" {
t.Errorf("Expected payload: %s", calls[0].Payload)
}
if calls[0].URL != "/redfish/v1/PowerEquipment/RackPDUs/1/OutletGroups/Rack5Storage/OutletGroup.ResetMetrics" {
t.Errorf("Expected target URL: %s", calls[0].URL)
}
}
// TestOutletGroupPowerControl tests the OutletGroup PowerControl call.
func TestOutletGroupPowerControl(t *testing.T) {
var result OutletGroup
err := json.NewDecoder(strings.NewReader(outletGroupBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
err = result.PowerControl(OffPowerState)
if err != nil {
t.Errorf("Error making PowerControl call: %s", err)
}
calls := testClient.CapturedCalls()
if len(calls) != 1 {
t.Errorf("Expected one call to be made, captured: %#v", calls)
}
if !strings.Contains(calls[0].Payload, "PowerState:Off") {
t.Errorf("Expected payload: %s", calls[0].Payload)
}
if calls[0].URL != "/redfish/v1/PowerEquipment/RackPDUs/1/OutletGroups/Rack5Storage/OutletGroup.PowerControl" {
t.Errorf("Expected target URL: %s", calls[0].URL)
}
}