forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventdestination_test.go
120 lines (99 loc) · 3.06 KB
/
eventdestination_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var eventDestinationBody = `{
"@odata.context": "/redfish/v1/$metadata#EventDestination.EventDestination",
"@odata.type": "#EventDestination.v1_0_0.EventDestination",
"@odata.id": "/redfish/v1/EventDestination",
"Id": "EventDestination-1",
"Name": "EventDestinationOne",
"Description": "EventDestination One",
"Context": "MyContext",
"Destination": "http://example.com/events",
"EventFormatType": "MetricReport",
"EventTypes":[
"StatusChange",
"ResourceUpdated",
"ResourceAdded",
"ResourceRemoved",
"Alert"
],
"HttpHeaders": [],
"MessageIds": ["One", "Two"],
"Protocol": "Redfish",
"RegistryPrefixes": ["ONE_", "TWO_"],
"ResourceTypes": ["one", "two"],
"SubordinateResources": false,
"SubscriptionType": "SSE"
}`
var eventDestinationsBody = `{
"@odata.context": "/redfish/v1/$metadata#EventDestinationCollection.EventDestinationCollection",
"@odata.etag": "W/\"AA6D42B0\"",
"@odata.id": "/redfish/v1/EventService/Subscriptions/",
"@odata.type": "#EventDestinationCollection.EventDestinationCollection",
"Description": "User Event Subscriptions",
"Name": "EventSubscriptions",
"Members": [
{
"@odata.id": "/redfish/v1/EventService/Subscriptions/EventDestination-1/"
}
],
"[email protected]": 1
}`
// TestEventDestination tests the parsing of EventDestination objects.
func TestEventDestination(t *testing.T) {
var result EventDestination
err := json.NewDecoder(strings.NewReader(eventDestinationBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "EventDestination-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "EventDestinationOne" {
t.Errorf("Received invalid name: %s", result.Name)
}
if len(result.HTTPHeaders) != 0 {
t.Errorf("Expected 0 headers, got: %d", len(result.HTTPHeaders))
}
if result.EventFormatType != MetricReportEventFormatType {
t.Errorf("Invalid event format type: %s", result.EventFormatType)
}
if result.Protocol != RedfishEventDestinationProtocol {
t.Errorf("Invalid event protocol: %s", result.Protocol)
}
if result.SubordinateResources {
t.Error("Subordinate resources should be False")
}
for _, et := range result.EventTypes {
if !et.IsValidEventType() {
t.Errorf("invalid event type: %s", et)
}
}
}
// TestEventDestinationUpdate tests the Update call.
func TestEventDestinationUpdate(t *testing.T) {
var result EventDestination
err := json.NewDecoder(strings.NewReader(eventDestinationBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
result.Context = "NewContext"
err = result.Update()
if err != nil {
t.Errorf("Error making Update call: %s", err)
}
calls := testClient.CapturedCalls()
if !strings.Contains(calls[0].Payload, "Context:NewContext") {
t.Errorf("Unexpected Context update payload: %s", calls[0].Payload)
}
}