forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessageregistry_test.go
218 lines (199 loc) · 7.09 KB
/
messageregistry_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
)
var messageRegistryBody = `{
"@odata.type": "#MessageRegistry.v1_2_0.MessageRegistry",
"Description": "This registry is an example.",
"Id": "MyRegistry.json",
"Name": "MyRegistry Registry",
"OwningEntity": "The vendor name",
"RegistryPrefix": "MyRegistry",
"RegistryVersion": "2.2.0",
"Language": "en",
"Messages": {
"FirstMessage": {
"Description": "Example of message with one arg.",
"Message": "This message has only one arg: %1",
"NumberOfArgs": 1,
"ParamTypes": [
"string"
],
"Resolution": "The resolution for the first message.",
"Severity": "OK"
},
"SecondMessage": {
"Description": "Example of message without args.",
"Message": "This message has no args.",
"NumberOfArgs": 0,
"ParamTypes": [],
"Resolution": "The resolution for the second message.",
"Severity": "Critical"
},
"ThirdMessage": {
"Description": "Example of message with two args.",
"Message": "This message has two args: %1 and %2",
"NumberOfArgs": 2,
"ParamTypes": [
"string",
"string"
],
"Resolution": "The resolution for the third message.",
"Severity": "Warning"
},
"MessageWithOem": {
"Description": "Example of message with Oem.",
"Message": "This message has Oem info.",
"NumberOfArgs": 0,
"Oem": {
"VendorName": {
"OemInfo1": "The Oem info 1.",
"OemInfoN": "The Oem info N."
}
},
"ParamTypes": [],
"Resolution": "The resolution for the message with Oem.",
"Severity": "Critical"
}
}
}`
// TestMessageRegistry tests the parsing of MessageRegistry objects.
func TestMessageRegistry(t *testing.T) { //nolint:funlen,gocyclo
var result MessageRegistry
err := json.NewDecoder(strings.NewReader(messageRegistryBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "MyRegistry.json" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Description != "This registry is an example." {
t.Errorf("Received invalid Description: %s", result.Description)
}
if result.Language != "en" {
t.Errorf("Received invalid Language: %s", result.Language)
}
if result.Name != "MyRegistry Registry" {
t.Errorf("Received invalid Name: %s", result.Name)
}
if result.ODataType != "#MessageRegistry.v1_2_0.MessageRegistry" {
t.Errorf("Received invalid ODataType: %s", result.ODataType)
}
if result.OwningEntity != "The vendor name" {
t.Errorf("Received invalid OwningEntity: %s", result.OwningEntity)
}
if result.RegistryPrefix != "MyRegistry" {
t.Errorf("Received invalid RegistryPrefix: %s", result.RegistryPrefix)
}
if result.RegistryVersion != "2.2.0" {
t.Errorf("Received invalid RegistryVersion: %s", result.RegistryVersion)
}
// test the messages
if len(result.Messages) != 4 {
t.Errorf("Received invalid number of Messages: %d", len(result.Messages))
}
// FirstMessage
messageKey := "FirstMessage"
if m, ok := result.Messages[messageKey]; ok {
if m.Description != "Example of message with one arg." {
t.Errorf("Received invalid Description: %s for the messageKey: %s", m.Description, messageKey)
}
if m.Message != "This message has only one arg: %1" {
t.Errorf("Received invalid Message: %s for the messageKey: %s", m.Message, messageKey)
}
if m.NumberOfArgs != 1 {
t.Errorf("Received invalid NumberOfArgs: %d for the messageKey: %s", m.NumberOfArgs, messageKey)
}
if m.ParamTypes[0] != "string" {
t.Errorf("Received invalid ParamTypes: %s for the messageKey: %s", m.ParamTypes[0], messageKey)
}
if m.Resolution != "The resolution for the first message." {
t.Errorf("Received invalid Resolution: %s for the messageKey: %s", m.Resolution, messageKey)
}
if m.Severity != "OK" {
t.Errorf("Received invalid Severity: %s for the messageKey: %s", m.Severity, messageKey)
}
} else {
t.Errorf("MessageKey %s not found.", messageKey)
}
// SecondMessage
messageKey = "SecondMessage"
if m, ok := result.Messages[messageKey]; ok {
if m.Description != "Example of message without args." {
t.Errorf("Received invalid Description: %s for the messageKey: %s", m.Description, messageKey)
}
if m.Message != "This message has no args." {
t.Errorf("Received invalid Message: %s for the messageKey: %s", m.Message, messageKey)
}
if m.NumberOfArgs != 0 {
t.Errorf("Received invalid NumberOfArgs: %d for the messageKey: %s", m.NumberOfArgs, messageKey)
}
if len(m.ParamTypes) > 0 {
t.Errorf("Received invalid ParamTypes: %v for the messageKey: %s", m.ParamTypes, messageKey)
}
if m.Resolution != "The resolution for the second message." {
t.Errorf("Received invalid Resolution: %s for the messageKey: %s", m.Resolution, messageKey)
}
if m.Severity != "Critical" {
t.Errorf("Received invalid Severity: %s for the messageKey: %s", m.Severity, messageKey)
}
} else {
t.Errorf("MessageKey %s not found.", messageKey)
}
// ThirdMessage
messageKey = "ThirdMessage"
if m, ok := result.Messages[messageKey]; ok {
if m.Description != "Example of message with two args." {
t.Errorf("Received invalid Description: %s for the messageKey: %s", m.Description, messageKey)
}
if m.Message != "This message has two args: %1 and %2" {
t.Errorf("Received invalid Message: %s for the messageKey: %s", m.Message, messageKey)
}
if m.NumberOfArgs != 2 {
t.Errorf("Received invalid NumberOfArgs: %d for the messageKey: %s", m.NumberOfArgs, messageKey)
}
if m.ParamTypes[0] != "string" {
t.Errorf("Received invalid ParamTypes[0]: %s for the messageKey: %s", m.ParamTypes[0], messageKey)
}
if m.ParamTypes[1] != "string" {
t.Errorf("Received invalid ParamTypes[1]: %s for the messageKey: %s", m.ParamTypes[1], messageKey)
}
if m.Resolution != "The resolution for the third message." {
t.Errorf("Received invalid Resolution: %s for the messageKey: %s", m.Resolution, messageKey)
}
if m.Severity != "Warning" {
t.Errorf("Received invalid Severity: %s for the messageKey: %s", m.Severity, messageKey)
}
} else {
t.Errorf("MessageKey %s not found.", messageKey)
}
// MessageWithOem
messageKey = "MessageWithOem"
if m, ok := result.Messages[messageKey]; ok {
if m.Description != "Example of message with Oem." {
t.Errorf("Received invalid Description: %s for the messageKey: %s", m.Description, messageKey)
}
if m.Message != "This message has Oem info." {
t.Errorf("Received invalid Message: %s for the messageKey: %s", m.Message, messageKey)
}
if m.NumberOfArgs != 0 {
t.Errorf("Received invalid NumberOfArgs: %d for the messageKey: %s", m.NumberOfArgs, messageKey)
}
if len(m.ParamTypes) > 0 {
t.Errorf("Received invalid ParamTypes: %v for the messageKey: %s", m.ParamTypes, messageKey)
}
if m.Resolution != "The resolution for the message with Oem." {
t.Errorf("Received invalid Resolution: %s for the messageKey: %s", m.Resolution, messageKey)
}
if m.Severity != "Critical" {
t.Errorf("Received invalid Severity: %s for the messageKey: %s", m.Severity, messageKey)
}
} else {
t.Errorf("MessageKey %s not found.", messageKey)
}
}