forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmediacontroller_test.go
98 lines (84 loc) · 2.56 KB
/
mediacontroller_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var mediaControllerBody = `{
"@odata.type": "#MediaController.v1_3_1.MediaController",
"Id": "MediaController1",
"Name": "Media Controller 1",
"MediaControllerType": "Memory",
"Manufacturer": "Contoso",
"Model": "Contoso MediaController",
"SerialNumber": "2M220100SL",
"Status": {
"State": "Enabled",
"Health": "OK"
},
"UUID": "41784113-ed6b-2284-1414-916520dc1dd1",
"Ports": {
"@odata.id": "/redfish/v1/Chassis/GenZ/MediaControllers/1/Ports"
},
"Actions": {
"#MediaController.Reset": {
"target": "/redfish/v1/Chassis/GenZ/MediaControllers/1/Actions/MediaController.Reset",
"[email protected]": [
"ForceRestart"
]
}
},
"Links": {
"Endpoints": [
{
"@odata.id": "/redfish/v1/Fabrics/GenZ/Endpoints/1"
}
],
"MemoryDomains": [
{
"@odata.id": "/redfish/v1/Chassis/GenZ/MemoryDomains/1"
}
]
},
"@odata.id": "/redfish/v1/Chassis/GenZ/MediaControllers/1"
}`
// TestMediaController tests the parsing of MediaController objects.
func TestMediaController(t *testing.T) {
var result MediaController
err := json.NewDecoder(strings.NewReader(mediaControllerBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertEquals(t, "MediaController1", result.ID)
assertEquals(t, "Media Controller 1", result.Name)
assertEquals(t, "41784113-ed6b-2284-1414-916520dc1dd1", result.UUID)
assertEquals(t, "/redfish/v1/Chassis/GenZ/MediaControllers/1/Ports", result.ports)
assertEquals(t, "/redfish/v1/Fabrics/GenZ/Endpoints/1", result.endpoints[0])
assertEquals(t, "/redfish/v1/Chassis/GenZ/MemoryDomains/1", result.memoryDomains[0])
assertEquals(t, "/redfish/v1/Chassis/GenZ/MediaControllers/1/Actions/MediaController.Reset", result.resetTarget)
}
// TestMediaControllerReset tests the MediaController Reset call.
func TestMediaControllerReset(t *testing.T) {
var result MediaController
err := json.NewDecoder(strings.NewReader(applicationBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
err = result.Reset(OnResetType)
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, "On") {
t.Errorf("Expected reset type not found in payload: %s", calls[0].Payload)
}
}