forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateservice_test.go
119 lines (108 loc) · 3.58 KB
/
updateservice_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var simpleUpdateBody = `{
"@odata.context": "/redfish/v1/$metadata#UpdateService.UpdateService",
"@odata.id": "/redfish/v1/UpdateService",
"@odata.type": "#UpdateService.v1_6_0.UpdateService",
"Actions": {
"#UpdateService.SimpleUpdate": {
"[email protected]": [
"HTTP"
],
"target": "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate"
},
"Oem": {
"DellUpdateService.v1_0_0#DellUpdateService.Install": {
"[email protected]": [
"Now",
"NowAndReboot",
"NextReboot"
],
"target": "/redfish/v1/UpdateService/Actions/Oem/DellUpdateService.Install"
}
}
},
"Description": "Represents the properties for the Update Service",
"FirmwareInventory": {
"@odata.id": "/redfish/v1/UpdateService/FirmwareInventory"
},
"HttpPushUri": "/redfish/v1/UpdateService/FirmwareInventory",
"Id": "UpdateService",
"Name": "Update Service"
}`
func TestUpdateService(t *testing.T) {
var result UpdateService
assertMessage := func(t testing.TB, got string, want string) {
t.Helper()
if got != want {
t.Errorf("got %s, want %s", got, want)
}
}
t.Run("Check default redfish fields", func(t *testing.T) {
c := &common.TestClient{}
result.SetClient(c)
err := json.NewDecoder(strings.NewReader(simpleUpdateBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertMessage(t, result.firmwareInventory, "/redfish/v1/UpdateService/FirmwareInventory")
assertMessage(t, result.HTTPPushURI, "/redfish/v1/UpdateService/FirmwareInventory")
assertMessage(t, result.TransferProtocol[0], "HTTP")
assertMessage(t, result.simpleUpdateTarget, "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate")
})
}
var startUpdateBody = `{
"@odata.type": "#UpdateService.v1_8_0.UpdateService",
"@odata.id": "/redfish/v1/UpdateService",
"Id": "UpdateService",
"Name": "Update Service",
"Description": "Service for updating firmware and includes inventory of firmware",
"Status": {
"State": "Enabled",
"Health": "OK",
"HealthRollup": "OK"
},
"ServiceEnabled": true,
"MultipartHttpPushUri": "/redfish/v1/UpdateService/upload",
"FirmwareInventory": {
"@odata.id": "/redfish/v1/UpdateService/FirmwareInventory"
},
"Actions": {
"Oem": {},
"#UpdateService.SimpleUpdate": {
"target": "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate",
"@Redfish.ActionInfo": "/redfish/v1/UpdateService/SimpleUpdateActionInfo"
},
"#UpdateService.StartUpdate": {
"target": "/redfish/v1/UpdateService/Actions/UpdateService.StartUpdate"
}
},
"Oem": {}
}
}`
func TestUpdateServiceStartUpdate(t *testing.T) {
var result UpdateService
assertMessage := func(t testing.TB, got string, want string) {
t.Helper()
if got != want {
t.Errorf("got %s, want %s", got, want)
}
}
t.Run("Check UpdateService.StartUpdate field", func(t *testing.T) {
c := &common.TestClient{}
result.SetClient(c)
err := json.NewDecoder(strings.NewReader(startUpdateBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertMessage(t, result.startUpdateTarget, "/redfish/v1/UpdateService/Actions/UpdateService.StartUpdate")
})
}