forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory_test.go
160 lines (139 loc) · 3.81 KB
/
memory_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var memoryBody = `{
"@odata.context": "/redfish/v1/$metadata#Memory.Memory",
"@odata.id": "/redfish/v1/Systems/System-1/Memory/NVRAM4",
"@odata.type": "#Memory.v1_2_0.Memory",
"Name": "Memory",
"Id": "NVRAM4",
"Links": {
"Chassis": {
"@odata.id": "/redfish/v1/Chassis/Chassis-1"
}
},
"AllocationAlignmentMiB": 1024,
"AllocationIncrementMiB": 1024,
"AllowedSpeedsMHz": [3200],
"Assembly": {
"@odata.id": "/redfish/v1/Assembly/1"
},
"BaseModuleType": "SO_DIMM",
"BusWidthBits": 1024,
"CacheSizeMiB": 256,
"CapacityMiB": 2097152,
"ConfigurationLocked": false,
"DataWidthBits": 256,
"DeviceLocator": "Inside",
"ErrorCorrection": "SingleBitECC",
"FirmwareApiVersion": "1.0",
"FirmwareRevision": "3",
"IsRankSpareEnabled": false,
"IsSpareDeviceEnabled": false,
"Location": {
"PartLocation": {
"LocationType": "Slot",
"ServiceLabel": "DIMM 5",
"LocationOrdinalValue": 4
}
},
"LogicalSizeMiB": 2097152,
"Manufacturer": "Generic",
"MaxTDPMilliWatts": [0],
"MemoryDeviceType": "DDR4",
"MemoryLocation": {
"Channel": 1,
"MemoryController": 2,
"Slot": 3,
"Socket": 4
},
"MemoryMedia": ["DRAM"],
"MemoryType": "NVDIMM_N",
"Metrics": {
"@odata.id": "/redfish/v1/Systems/1/Memory/1/MemoryMetrics"
},
"OperatingMemoryModes": [
"PMEM"
],
"OperatingSpeedMhz": 3200,
"PowerManagementPolicy": {
"AveragePowerBudgetMilliWatts": 42,
"MaxTDPMilliWatts": 12,
"PeakPowerBudgetMilliWatts": 84,
"PolicyEnabled": false
},
"RankCount": 12,
"SerialNumber": "TJ27JXQY",
"SecurityCapabilities": {
"ConfigurationLockCapable": false,
"DataLockCapable": false,
"MaxPassphraseCount": 2,
"PassphraseCapable": true,
"PassphraseLockLimit": 2
},
"SecurityState": "Unlocked",
"Status": {
"Health": "OK",
"State": "Enabled"
},
"VendorID": "Generic"
}`
// TestMemory tests the parsing of Memory objects.
func TestMemory(t *testing.T) {
var result Memory
err := json.NewDecoder(strings.NewReader(memoryBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "NVRAM4" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "Memory" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.chassis != TestChassisPath {
t.Errorf("Invalid chassis link: %s", result.chassis)
}
if result.MemoryType != NVDIMMNMemoryType {
t.Errorf("Invalid memory type: %s", result.MemoryType)
}
if result.MemoryDeviceType != DDR4MemoryDeviceType {
t.Errorf("Invalid memory device type: %s", result.MemoryDeviceType)
}
if result.OperatingMemoryModes[0] != PMEMOperatingMemoryModes {
t.Errorf("Invalid operating memory mode results: %s", result.OperatingMemoryModes)
}
if result.PowerManagementPolicy.AveragePowerBudgetMilliWatts != 42 {
t.Errorf("Invalid power management policy average power budget: %d",
result.PowerManagementPolicy.AveragePowerBudgetMilliWatts)
}
if result.SecurityCapabilities.DataLockCapable {
t.Error("Security capabilities data lock capable should be false")
}
}
// TestMemoryUpdate tests the Update call.
func TestMemoryUpdate(t *testing.T) {
var result Memory
err := json.NewDecoder(strings.NewReader(memoryBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
result.SecurityState = FrozenSecurityStates
err = result.Update()
if err != nil {
t.Errorf("Error making Update call: %s", err)
}
calls := testClient.CapturedCalls()
if !strings.Contains(calls[0].Payload, "SecurityState:Frozen") {
t.Errorf("Unexpected SecurityState update payload: %s", calls[0].Payload)
}
}