forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompositionservice_test.go
112 lines (89 loc) · 2.91 KB
/
compositionservice_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var compositionServiceBody = `{
"@odata.context": "/redfish/v1/$metadata#CompositionService.CompositionService",
"@odata.type": "#CompositionService.v1_0_0.CompositionService",
"@odata.id": "/redfish/v1/CompositionService",
"Id": "CompositionService-1",
"Name": "Composition Service",
"Description": "Composition Service",
"Status": {
"State": "Enabled",
"Health": "OK"
},
"AllowOverprovisioning": true,
"AllowZoneAffinity": false,
"ServiceEnabled": true,
"ResourceBlocks": {
"@odata.id": "/redfish/v1/CompositionService/ResourceBlocks"
},
"ResourceZones": {
"@odata.id": "/redfish/v1/CompositionService/ResourceZones"
}
}`
// TestCompositionService tests the parsing of CompositionService objects.
func TestCompositionService(t *testing.T) {
var result CompositionService
err := json.NewDecoder(strings.NewReader(compositionServiceBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "CompositionService-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "Composition Service" {
t.Errorf("Received invalid name: %s", result.Name)
}
if !result.AllowOverprovisioning {
t.Error("Expected AllowOverprovisioning to be true")
}
if result.AllowZoneAffinity {
t.Error("Expected AllowZoneAffinity to be false")
}
if !result.ServiceEnabled {
t.Error("Expected ServiceEnabled to be true")
}
if result.Status.Health != common.OKHealth {
t.Errorf("Received invalid health status: %s", result.Status.Health)
}
if result.resourceBlocks != "/redfish/v1/CompositionService/ResourceBlocks" {
t.Errorf("Received invalid resource blocks reference: %s", result.resourceBlocks)
}
if result.resourceZones != "/redfish/v1/CompositionService/ResourceZones" {
t.Errorf("Received invalid resource zones reference: %s", result.resourceZones)
}
}
// TestCompositionServiceUpdate tests the Update call.
func TestCompositionServiceUpdate(t *testing.T) {
var result CompositionService
err := json.NewDecoder(strings.NewReader(compositionServiceBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
result.ServiceEnabled = false
result.AllowOverprovisioning = false
err = result.Update()
if err != nil {
t.Errorf("Error making Update call: %s", err)
}
calls := testClient.CapturedCalls()
if len(calls) != 1 {
t.Errorf("Expected one call to be made, captured: %v", calls)
}
if !strings.Contains(calls[0].Payload, "AllowOverprovisioning:false") {
t.Errorf("Unexpected AllowOverprovisioning update payload: %s", calls[0].Payload)
}
if !strings.Contains(calls[0].Payload, "ServiceEnabled:false") {
t.Errorf("Unexpected ServiceEnabled update payload: %s", calls[0].Payload)
}
}