forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollection_test.go
57 lines (49 loc) · 1.25 KB
/
collection_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package common
import (
"encoding/json"
"fmt"
"strings"
"testing"
)
var collectionBody = strings.NewReader(
`{
"@odata.context": "/redfish/v1/$metadata#ComputerSystemCollection.ComputerSystemCollection",
"@odata.id": "/redfish/v1/ComputerSystemCollection",
"@odata.type": "#ComputerSystemCollection.1.0.0.ComputerSystemCollection",
"Name": "Test Collection",
"Links": {
"[email protected]": 2,
"Members": [
{
"@odata.id": "/redfish/v1/Systems/System-1"
},
{
"@odata.id": "/redfish/v1/Systems/System-2"
}
]
}
}`)
// TestCollection tests the parsing of Collections.
func TestCollection(t *testing.T) {
var result Collection
err := json.NewDecoder(collectionBody).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.Name != "Test Collection" {
t.Errorf("Received invalid name: %s", result.Name)
}
if len(result.ItemLinks) != 2 {
t.Errorf("Expected 2 items in collection, got %d", len(result.ItemLinks))
}
linkRoot := "/redfish/v1/Systems/System-%d"
for i, item := range result.ItemLinks {
endpoint := fmt.Sprintf(linkRoot, i+1)
if item != endpoint {
t.Errorf("Expected link to '%s', got '%s'", endpoint, item)
}
}
}