forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume_test.go
97 lines (82 loc) · 2.36 KB
/
volume_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var volumeBody = `{
"@odata.type": "#Volume.v1_10_0.Volume",
"Id": "2",
"Name": "Virtual Disk 2",
"Status": {
"State": "Enabled",
"Health": "OK"
},
"Encrypted": false,
"RAIDType": "RAID0",
"CapacityBytes": 107374182400,
"Identifiers": [
{
"DurableNameFormat": "UUID",
"DurableName": "0324c96c-8031-4f5e-886c-50cd90aca854"
}
],
"Links": {
"Drives": [
{
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Storage/1/Drives/3D58ECBC375FD9F2"
}
]
},
"Actions": {
"#Volume.Initialize": {
"target": "/redfish/v1/Systems/3/Storage/RAIDIntegrated/Volumes/1/Actions/Volume.Initialize",
"[email protected]": [
"Fast",
"Slow"
]
}
},
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Storage/1/Volumes/2"
}`
// TesVolume tests the parsing of Volume objects.
func TestVolume(t *testing.T) {
var result Volume
err := json.NewDecoder(strings.NewReader(volumeBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertEquals(t, "2", result.ID)
assertEquals(t, "RAID0", string(result.RAIDType))
assertEquals(t, "UUID", string(result.Identifiers[0].DurableNameFormat))
assertEquals(t, "0324c96c-8031-4f5e-886c-50cd90aca854", result.Identifiers[0].DurableName)
assertEquals(t, "/redfish/v1/Systems/437XR1138R2/Storage/1/Drives/3D58ECBC375FD9F2", result.drives[0])
}
// TestVolumeInitialize tests the Volume Initialize call.
func TestVolumeInitialize(t *testing.T) {
var result Volume
err := json.NewDecoder(strings.NewReader(volumeBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
err = result.Initialize(BackgroundInitializeMethod, FastInitializeType)
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, "InitializeMethod:Background") {
t.Errorf("Expected reset type not found in payload: %s", calls[0].Payload)
}
if !strings.Contains(calls[0].Payload, "InitializeType:Fast") {
t.Errorf("Expected reset type not found in payload: %s", calls[0].Payload)
}
}