forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrive_test.go
185 lines (158 loc) · 4.5 KB
/
drive_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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var driveBody = `{
"@odata.context": "/redfish/v1/$metadata#Drive.Drive",
"@odata.type": "#Drive.v1_0_0.Drive",
"@odata.id": "/redfish/v1/Drive",
"Id": "Drive-1",
"Name": "Drive One",
"Description": "One drive",
"Actions": {
"#Drive.SecureErase": {
"target": "/redfish/v1/Chassis/NVMeChassis/Disk.Bay.0/Actions/Drive.SecureErase"
}
},
"Assembly": {
"@odata.id": "/redfish/v1/Assembly/Assembly-1"
},
"AssetTag": "Asset 1",
"BlockSizeBytes": 512,
"CapableSpeedGbs": 40,
"CapacityBytes": 1099511627776,
"EncryptionAbility": "SelfEncryptingDrive",
"EncryptionStatus": "Unlocked",
"FailurePredicted": false,
"HotSpareMode": "Revertible",
"HotSpareType": "Chassis",
"Identifiers": [
{
"DurableName": "5000D3100101D52E",
"DurableNameFormat": "FC_WWN"
}
],
"IndicatorLED": "Blinking",
"Links": {
"Chassis": {
"@odata.id": "/redfish/v1/Chassis/Chassis-1"
},
"Endpoints": [],
"[email protected]": 0,
"PCIeFunctions": [
{
"@odata.id": "/redfish/v1/PCIeFunctions/PCIeFunction-1"
}
],
"[email protected]": 1,
"Volumes": [
{
"@odata.id": "/redfish/v1/Volumes/Volume-1"
}
],
"[email protected]": 1
},
"Manufacturer": "Joe's Storage",
"MediaType": "SSD",
"Model": "Storage One",
"Multipath": true,
"NegotiatedSpeedGbps": 10,
"Operations": [],
"PartNumber": "12345",
"PhysicalLocation": {
"PartLocation": {
"LocationOrdinalValue": 0,
"LocationType": "Slot"
}
},
"PredictedMediaLifeLeftPercent": 100,
"Protocol": "FC",
"Revision": "2.0",
"RotationSpeedRPM": 5200,
"SKU": "123456",
"SerialNumber": "1234567",
"Status": {
"State": "Enabled",
"Health": "OK"
},
"StatusIndicator": "Hotspare",
"WriteCacheEnabled": true
}`
// TestDrive tests the parsing of Drive objects.
func TestDrive(t *testing.T) {
var result Drive
err := json.NewDecoder(strings.NewReader(driveBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "Drive-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "Drive One" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.assembly != "/redfish/v1/Assembly/Assembly-1" {
t.Errorf("Incorrect assembly link: %s", result.assembly)
}
if result.BlockSizeBytes != 512 {
t.Errorf("Incorrect block size bytes: %d", result.BlockSizeBytes)
}
if result.CapableSpeedGbs != 40 {
t.Errorf("Incorrect capable speed: %f", result.CapableSpeedGbs)
}
if result.CapacityBytes != 1099511627776 {
t.Errorf("Incorrect capacity: %d", result.CapacityBytes)
}
if result.EncryptionAbility != "SelfEncryptingDrive" {
t.Errorf("Incorrect encryption ability: %s", result.EncryptionAbility)
}
if result.EncryptionStatus != "Unlocked" {
t.Errorf("Incorrect encryption status: %s", result.EncryptionStatus)
}
if result.FailurePredicted {
t.Error("Failure predicted should be false.")
}
if result.chassis != TestChassisPath {
t.Errorf("Invalid chassis link: %s", result.chassis)
}
if result.secureEraseTarget != "/redfish/v1/Chassis/NVMeChassis/Disk.Bay.0/Actions/Drive.SecureErase" {
t.Errorf("Invalid SecureErase target: %s", result.secureEraseTarget)
}
}
// TestDriveUpdate tests the Update call.
func TestDriveUpdate(t *testing.T) {
var result Drive
err := json.NewDecoder(strings.NewReader(driveBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
result.AssetTag = TestAssetTag
result.IndicatorLED = common.LitIndicatorLED
result.StatusIndicator = HotspareStatusIndicator
result.WriteCacheEnabled = false
err = result.Update()
if err != nil {
t.Errorf("Error making Update call: %s", err)
}
calls := testClient.CapturedCalls()
if !strings.Contains(calls[0].Payload, "AssetTag:TestAssetTag") {
t.Errorf("Unexpected AssetTag update payload: %s", calls[0].Payload)
}
if !strings.Contains(calls[0].Payload, "IndicatorLED:Lit") {
t.Errorf("Unexpected IndicatorLED update payload: %s", calls[0].Payload)
}
if strings.Contains(calls[0].Payload, "StatusIndicator") {
t.Errorf("Unexpected update for StatusIndicator in payload: %s", calls[0].Payload)
}
if !strings.Contains(calls[0].Payload, "WriteCacheEnabled:false") {
t.Errorf("Unexpected WriteCacheEnabled update payload: %s", calls[0].Payload)
}
}