forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfan_test.go
70 lines (61 loc) · 1.64 KB
/
fan_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
)
var fanBody = `{
"@odata.type": "#Fan.v1_5_1.Fan",
"Id": "Bay1",
"Name": "Fan Bay 1",
"Status": {
"State": "Enabled",
"Health": "OK"
},
"PhysicalContext": "Chassis",
"Model": "RKS-440DC",
"Manufacturer": "Contoso Fans",
"PartNumber": "23456-133",
"SparePartNumber": "93284-133",
"LocationIndicatorActive": true,
"HotPluggable": true,
"SpeedPercent": {
"Reading": 45,
"SpeedRPM": 2200,
"DataSourceUri": "/redfish/v1/Chassis/1U/Sensors/FanBay1"
},
"Location": {
"PartLocation": {
"ServiceLabel": "Chassis Fan Bay 1",
"LocationType": "Bay",
"LocationOrdinalValue": 0
}
},
"@odata.id": "/redfish/v1/Chassis/1U/ThermalSubsystem/Fans/Bay1"
}`
// TestFan tests the parsing of Fan objects.
func TestFan(t *testing.T) {
var result Fan
err := json.NewDecoder(strings.NewReader(fanBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertEquals(t, "Bay1", result.ID)
assertEquals(t, "Fan Bay 1", result.Name)
assertEquals(t, "Chassis", string(result.PhysicalContext))
assertEquals(t, "RKS-440DC", result.Model)
assertEquals(t, "Chassis Fan Bay 1", result.Location.PartLocation.ServiceLabel)
assertEquals(t, "/redfish/v1/Chassis/1U/Sensors/FanBay1", result.SpeedPercent.DataSourceURI)
if !result.LocationIndicatorActive {
t.Error("Expected location indicator to be active")
}
if !result.HotPluggable {
t.Error("Expected to be hot pluggable")
}
if result.SpeedPercent.SpeedRPM != 2200 {
t.Errorf("Unexpected SpeedPercent.SpeedRPM: %.2f", result.SpeedPercent.SpeedRPM)
}
}