forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpointgroup_test.go
84 lines (69 loc) · 2.17 KB
/
endpointgroup_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var endpointGroupBody = `{
"@odata.type": "#EndpointGroup.v1_3_3.EndpointGroup",
"Id": "1",
"Name": "Endpoint group for all initiators",
"GroupType": "Initiator",
"Links": {
"Endpoints": [
{
"@odata.id": "/redfish/v1/Fabrics/NVMeoF/Endpoints/Initiator1"
},
{
"@odata.id": "/redfish/v1/Fabrics/NVMeoF/Endpoints/Initiator2"
}
],
"Connections": [
{
"@odata.id": "/redfish/v1/Fabrics/NVMeoF/Connections/3"
}
]
},
"@odata.id": "/redfish/v1/Fabrics/NVMeoF/EndpointGroups/1"
}`
// TestEndpointGroup tests the parsing of EndpointGroup objects.
func TestEndpointGroup(t *testing.T) {
var result EndpointGroup
err := json.NewDecoder(strings.NewReader(endpointGroupBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertEquals(t, "1", result.ID)
assertEquals(t, "Endpoint group for all initiators", result.Name)
assertEquals(t, "Initiator", string(result.GroupType))
assertEquals(t, "/redfish/v1/Fabrics/NVMeoF/Endpoints/Initiator1", result.endpoints[0])
assertEquals(t, "/redfish/v1/Fabrics/NVMeoF/Endpoints/Initiator2", result.endpoints[1])
assertEquals(t, "/redfish/v1/Fabrics/NVMeoF/Connections/3", result.connections[0])
}
// TestEndpointGroupUpdate tests the Update call.
func TestEndpointGroupUpdate(t *testing.T) {
var result EndpointGroup
err := json.NewDecoder(strings.NewReader(endpointGroupBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
result.GroupType = TargetGroupType
result.TargetEndpointGroupIdentifier = 3
err = result.Update()
if err != nil {
t.Errorf("Error making Update call: %s", err)
}
calls := testClient.CapturedCalls()
if !strings.Contains(calls[0].Payload, "GroupType:Target") {
t.Errorf("Unexpected GroupType update payload: %s", calls[0].Payload)
}
if !strings.Contains(calls[0].Payload, "TargetEndpointGroupIdentifier:3") {
t.Errorf("Unexpected TargetEndpointGroupIdentifier update payload: %s", calls[0].Payload)
}
}