forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregate_test.go
128 lines (104 loc) · 3.59 KB
/
aggregate_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var aggregateBody = `{
"@odata.type": "#Aggregate.v1_0_2.Aggregate",
"Id": "Aggregate1",
"Name": "Aggregate One",
"ElementsCount": 2,
"Elements": [
{
"@odata.id": "/redfish/v1/Systems/cluster-node3"
},
{
"@odata.id": "/redfish/v1/Systems/cluster-node4"
}
],
"Actions": {
"#Aggregate.Reset": {
"target": "/redfish/v1/AggregationService/Aggregates/Aggregate1/Actions/Aggregate.Reset",
"@Redfish.ActionInfo": "/redfish/v1/AggregationService/Aggregates/Aggregate1/ResetActionInfo"
},
"#Aggregate.SetDefaultBootOrder": {
"target": "/redfish/v1/AggregationService/Aggregates/Aggregate1/Actions/Aggregate.SetDefaultBootOrder",
"@Redfish.ActionInfo": "/redfish/v1/AggregationService/Aggregates/Aggregate1/SetDefaultBootOrderActionInfo"
},
"#Aggregate.AddElements": {
"target": "/redfish/v1/AggregationService/Aggregates/Aggregate1/Actions/Aggregate.AddElements",
"@Redfish.ActionInfo": "/redfish/v1/AggregationService/Aggregates/Aggregate1/AddElementsActionInfo"
},
"#Aggregate.RemoveElements": {
"target": "/redfish/v1/AggregationService/Aggregates/Aggregate1/Actions/Aggregate.RemoveElements",
"@Redfish.ActionInfo": "/redfish/v1/AggregationService/Aggregates/Aggregate1/RemoveElementsActionInfo"
}
},
"@odata.id": "/redfish/v1/AggregationService/Aggregates/Aggregate1"
}`
// TestAggregate tests the parsing of Aggregate objects.
func TestAggregate(t *testing.T) {
var result Aggregate
err := json.NewDecoder(strings.NewReader(aggregateBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertEquals(t, "Aggregate1", result.ID)
assertEquals(t, "Aggregate One", result.Name)
if len(result.elements) != 2 {
t.Errorf("Expected 2 elements, got %#v", result.elements)
}
}
// TestAggregateReset tests the Aggregate reset call.
func TestAggregateReset(t *testing.T) {
var result Aggregate
err := json.NewDecoder(strings.NewReader(aggregateBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
err = result.Reset(5, 10, PowerCycleResetType)
if err != nil {
t.Errorf("Error making Reset 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, "ResetType:PowerCycle") {
t.Errorf("Unexpected reset payload: %s", calls[0].Payload)
}
if !strings.Contains(calls[0].Payload, "BatchSize:5") {
t.Errorf("Expected 'BatchSize' to be present and set to 5 %s", calls[0].Payload)
}
if !strings.Contains(calls[0].Payload, "DelayBetweenBatchesInSeconds:10") {
t.Errorf("Expected 'DelayBetweenBatchesInSeconds' to be present and set to 10 %s", calls[0].Payload)
}
}
// TestAggregateSetDefaultBootOrder tests the Aggregate SetDefaultBootOrder call.
func TestAggregateSetDefaultBootOrder(t *testing.T) {
var result Aggregate
err := json.NewDecoder(strings.NewReader(aggregateBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
err = result.SetDefaultBootOrder()
if err != nil {
t.Errorf("Error making Reset 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 empty payload: %#v", calls[0].Payload)
}
}