forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemorymetrics_test.go
78 lines (67 loc) · 1.86 KB
/
memorymetrics_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
)
var memoryMetricsBody = strings.NewReader(
`{
"@odata.context": "/redfish/v1/$metadata#MemoryMetrics.MemoryMetrics",
"@odata.type": "#MemoryMetrics.v1_0_0.MemoryMetrics",
"@odata.id": "/redfish/v1/MemoryMetrics",
"Id": "MemoryMetrics-1",
"Name": "MemoryMetricsOne",
"Description": "MemoryMetrics One",
"BlockSizeBytes": 512,
"CurrentPeriod": {
"BlocksRead": 123456,
"BlockWritten": 54321
},
"HealthData": {
"AlarmTrips": {
"AddressParityError": false,
"CorrectableECCError": false,
"SpareBlock": false,
"Temperature": true,
"UncorrectableECCError": false
},
"DataLossDetected": false,
"LastShutdownSuccess": true,
"PerformanceDegraded": false,
"PredictedMediaLifeLeftPercent": 85,
"RemainingSpareblockPercentage": 95
},
"LifeTime": {
"BlocksRead": 1234567890,
"BlocksWritten": 9876543210
}
}`)
// TestMemoryMetrics tests the parsing of MemoryMetrics objects.
func TestMemoryMetrics(t *testing.T) {
var result MemoryMetrics
err := json.NewDecoder(memoryMetricsBody).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "MemoryMetrics-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "MemoryMetricsOne" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.CurrentPeriod.BlocksRead != 123456 {
t.Errorf("Invalid current period blocks read: %d", result.CurrentPeriod.BlocksRead)
}
if result.HealthData.AlarmTrips.AddressParityError {
t.Error("Address parity error should be false")
}
if result.HealthData.DataLossDetected {
t.Error("Data loss detected should be false")
}
if result.LifeTime.BlocksWritten != 9876543210 {
t.Errorf("Invalid lifetime blocks written: %d", result.LifeTime.BlocksWritten)
}
}