forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol_test.go
67 lines (57 loc) · 1.65 KB
/
control_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
)
var controlBody = `{
"@odata.type": "#Control.v1_5_0.Control",
"Id": "PowerLimit",
"Name": "System Power Limit",
"PhysicalContext": "Chassis",
"ControlType": "Power",
"ControlMode": "Automatic",
"SetPoint": 500,
"SetPointUnits": "W",
"AllowableMax": 1000,
"AllowableMin": 150,
"Sensor": {
"Reading": 374,
"DataSourceUri": "/redfish/v1/Chassis/1U/Sensors/TotalPower"
},
"Status": {
"Health": "OK",
"State": "Enabled"
},
"@odata.id": "/redfish/v1/Chassis/1U/Controls/PowerLimit"
}`
// TestControl tests the parsing of Control objects.
func TestControl(t *testing.T) {
var result Control
err := json.NewDecoder(strings.NewReader(controlBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertEquals(t, "PowerLimit", result.ID)
assertEquals(t, "System Power Limit", result.Name)
assertEquals(t, "Chassis", string(result.PhysicalContext))
assertEquals(t, "Power", string(result.ControlType))
assertEquals(t, "Automatic", string(result.ControlMode))
assertEquals(t, "W", result.SetPointUnits)
assertEquals(t, "/redfish/v1/Chassis/1U/Sensors/TotalPower", result.Sensor.DataSourceURI)
if result.SetPoint != 500 {
t.Errorf("Unexpected set point, got %.2f", result.SetPoint)
}
if result.AllowableMax != 1000 {
t.Errorf("Unexpected allowable max, got %.2f", result.AllowableMax)
}
if result.AllowableMin != 150 {
t.Errorf("Unexpected allowable min, got %.2f", result.AllowableMin)
}
if result.Sensor.Reading != 374 {
t.Errorf("Unexpected sensor reading, got %.2f", result.Sensor.Reading)
}
}