forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication_test.go
97 lines (81 loc) · 2.25 KB
/
application_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var applicationBody = `{
"@odata.type": "#Application.v1_0_0.Application",
"Id": "Logger",
"Name": "Logging Agent",
"Version": "1.5.1",
"Vendor": "Contoso",
"StartTime": "2021-10-29T10:42:38+06:00",
"Status": {
"State": "Enabled",
"Health": "OK"
},
"DestinationURIs": [
"https://listeners.contoso.org:8000/handler"
],
"MetricsURIs": [
"https://192.168.0.12:7000"
],
"Actions": {
"#Application.Reset": {
"target": "/redfish/v1/Systems/VM1/OperatingSystem/Applications/Logger/Actions/Application.Reset",
"[email protected]": [
"On",
"ForceOff",
"GracefulShutdown",
"GracefulRestart",
"ForceRestart",
"ForceOn"
]
}
},
"@odata.id": "/redfish/v1/Systems/VM1/OperatingSystem/Applications/Logger"
}`
// TestApplication tests the parsing of Application objects.
func TestApplication(t *testing.T) {
var result Application
err := json.NewDecoder(strings.NewReader(applicationBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
assertEquals(t, "Logger", result.ID)
assertEquals(t, "Logging Agent", result.Name)
assertEquals(t, "1.5.1", result.Version)
assertEquals(t, "Contoso", result.Vendor)
if len(result.DestinationURIs) != 1 {
t.Errorf("Expected 1 destination URI, got %#v", result.DestinationURIs)
}
if len(result.MetricsURIs) != 1 {
t.Errorf("Expected 1 metrics URI, got %#v", result.MetricsURIs)
}
}
// TestApplicationReset tests the Application Reset call.
func TestApplicationReset(t *testing.T) {
var result Application
err := json.NewDecoder(strings.NewReader(applicationBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
err = result.Reset(OnResetType)
if err != nil {
t.Errorf("Error making Reset 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, "On") {
t.Errorf("Expected reset type not found in payload: %s", calls[0].Payload)
}
}