-
Notifications
You must be signed in to change notification settings - Fork 119
/
serviceroot_test.go
242 lines (209 loc) · 6.04 KB
/
serviceroot_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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//
// SPDX-License-Identifier: BSD-3-Clause
//
package gofish
import (
"encoding/json"
"strings"
"testing"
)
var serviceRootBody = strings.NewReader(
`{
"@odata.context": "/redfish/v1/$metadata#ServiceRoot.ServiceRoot",
"@odata.type": "#ServiceRoot.v1_5_1.ServiceRoot",
"@odata.id": "/redfish/v1/ServiceRoot",
"Id": "ServiceRoot-1",
"Name": "ServiceRootOne",
"Description": "ServiceRoot One",
"AccountService": {
"@odata.id": "/redfish/v1/Accounts"
},
"CertificateService": {
"@odata.id": "/redfish/v1/Certificates"
},
"Chassis": {
"@odata.id": "/redfish/v1/Chassis"
},
"ComponentIntegrity": {
"@odata.id": "/redfish/v1/ComponentIntegrity"
},
"CompositionService": {
"@odata.id": "/redfish/v1/Compositions"
},
"EventService": {
"@odata.id": "/redfish/v1/Events"
},
"Fabrics": {
"@odata.id": "/redfish/v1/Fabrics"
},
"JobService": {
"@odata.id": "/redfish/v1/Jobs"
},
"JsonSchemas": {
"@odata.id": "/redfish/v1/JsonSchemas"
},
"Links": {
"Sessions": {
"@odata.id": "/redfish/v1/Sessions"
}
},
"Managers": {
"@odata.id": "/redfish/v1/Managers"
},
"Product": "Product One",
"ProtocolFeaturesSupported": {
"ExcerptQuery": true,
"ExpandQuery": {
"ExpandAll": true,
"Levels": true,
"Links": true,
"MaxLevels": 21,
"NoLinks": true
},
"FilterQuery": true,
"OnlyMemberQuery": true,
"SelectQuery": true
},
"RedfishVersion": "1.2.3",
"Registries": {
"@odata.id": "/redfish/v1/Registries"
},
"ResourceBlocks": {
"@odata.id": "/redfish/v1/ResourceBlocks"
},
"SessionService": {
"@odata.id": "/redfish/v1/SessionService"
},
"StorageServices": {
"@odata.id": "/redfish/v1/StorageServices"
},
"StorageSystems": {
"@odata.id": "/redfish/v1/StorageSystems"
},
"Systems": {
"@odata.id": "/redfish/v1/Systems"
},
"Tasks": {
"@odata.id": "/redfish/v1/Tasks"
},
"TelemetryService": {
"@odata.id": "/redfish/v1/TelemetryService"
},
"UUID": "ae058175-af1d-40fe-ad5b-c1ab79de2c65",
"UpdateService": {
"@odata.id": "/redfish/v1/UpdateService"
},
"Vendor": "Acme Services"
}`)
// TestServiceRoot tests the parsing of ServiceRoot objects.
func TestServiceRoot(t *testing.T) {
var result Service
err := json.NewDecoder(serviceRootBody).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "ServiceRoot-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "ServiceRootOne" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.accountService != "/redfish/v1/Accounts" {
t.Errorf("Invalid AccountService link: %s", result.accountService)
}
if result.certificateService != "/redfish/v1/Certificates" {
t.Errorf("Invalid CertificateService link: %s", result.certificateService)
}
if result.chassis != "/redfish/v1/Chassis" {
t.Errorf("Invalid Chassis link: %s", result.chassis)
}
if result.compositionService != "/redfish/v1/Compositions" {
t.Errorf("Invalid CompositionService link: %s", result.compositionService)
}
if result.eventService != "/redfish/v1/Events" {
t.Errorf("Invalid EventService link: %s", result.eventService)
}
if result.fabrics != "/redfish/v1/Fabrics" {
t.Errorf("Invalid Fabrics link: %s", result.fabrics)
}
if result.jobService != "/redfish/v1/Jobs" {
t.Errorf("Invalid JobService link: %s", result.jobService)
}
if result.jsonSchemas != "/redfish/v1/JsonSchemas" {
t.Errorf("Invalid JsonSchemas link: %s", result.jsonSchemas)
}
if result.sessions != "/redfish/v1/Sessions" {
t.Errorf("Invalid Sessions link: %s", result.sessions)
}
if result.managers != "/redfish/v1/Managers" {
t.Errorf("Invalid Managers link: %s", result.managers)
}
if !result.ProtocolFeaturesSupported.ExcerptQuery {
t.Error("ExcerptQuery should be true")
}
if result.registries != "/redfish/v1/Registries" {
t.Errorf("Invalid Registries link: %s", result.registries)
}
if result.resourceBlocks != "/redfish/v1/ResourceBlocks" {
t.Errorf("Invalid ResourceBlocks link: %s", result.resourceBlocks)
}
if result.sessionService != "/redfish/v1/SessionService" {
t.Errorf("Invalid SessionService link: %s", result.sessionService)
}
if result.storageServices != "/redfish/v1/StorageServices" {
t.Errorf("Invalid StorageServices link: %s", result.storageServices)
}
if result.storageSystems != "/redfish/v1/StorageSystems" {
t.Errorf("Invalid StorageSystems link: %s", result.storageSystems)
}
if result.systems != "/redfish/v1/Systems" {
t.Errorf("Invalid Systems link: %s", result.systems)
}
if result.tasks != "/redfish/v1/Tasks" {
t.Errorf("Invalid Tasks link: %s", result.tasks)
}
if result.telemetryService != "/redfish/v1/TelemetryService" {
t.Errorf("Invalid TelemetryService link: %s", result.telemetryService)
}
if result.updateService != "/redfish/v1/UpdateService" {
t.Errorf("Invalid UpdateService link: %s", result.updateService)
}
}
const oem = `{
"Dell": {
"@odata.context": "/redfish/v1/$metadata#DellServiceRoot.DellServiceRoot",
"@odata.type": "#DellServiceRoot.v1_0_0.DellServiceRoot",
"ManagerMACAddress": "4c:d9:8f:00:11:34",
"ServiceTag": "C3H3853"
}
}`
var serviceRootBodyOEM = strings.NewReader(
`{
"@odata.context": "/redfish/v1/$metadata#ServiceRoot.ServiceRoot",
"@odata.type": "#ServiceRoot.v1_5_1.ServiceRoot",
"@odata.id": "/redfish/v1/ServiceRoot",
"Id": "ServiceRoot-1",
"Name": "ServiceRootOne",
"Description": "ServiceRoot One",
"Oem":` + oem + `,
"Vendor": "Dell"
}`)
// TestServiceRootOEM tests the parsing of ServiceRoot objects with OEM field.
func TestServiceRootOEM(t *testing.T) {
var result Service
err := json.NewDecoder(serviceRootBodyOEM).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "ServiceRoot-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Oem == nil {
t.Error("Invalid Oem link")
}
oemExp := strings.TrimSpace(oem)
oemObt := strings.TrimSpace(string(result.Oem))
if oemExp != oemObt {
t.Errorf("Expect\n%s\n,Obtain\n%s", oemExp, oemObt)
}
}