forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogservice_test.go
107 lines (86 loc) · 2.61 KB
/
logservice_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var logServiceBody = `{
"@odata.context": "/redfish/v1/$metadata#LogService.LogService",
"@odata.type": "#LogService.v1_0_0.LogService",
"@odata.id": "/redfish/v1/LogService",
"Id": "LogService-1",
"Name": "LogServiceOne",
"Description": "LogService One",
"DateTime": "2012-03-07T14:44+06:00",
"Entries": {
"@odata.id": "/redfish/v1/LogEntryCollection"
},
"LogEntryType": "Event",
"MaxNumberOfRecords": 1000,
"OverWritePolicy": "WrapsWhenFull",
"ServiceEnabled": true,
"Status": {
"State": "Enabled",
"Health": "OK"
},
"Actions": {
"#LogService.ClearLog": {
"target": "/redfish/v1/Managers/BMC/LogServices/Log/Actions/LogService.ClearLog"
}
}
}`
// TestLogService tests the parsing of LogService objects.
func TestLogService(t *testing.T) {
var result LogService
err := json.NewDecoder(strings.NewReader(logServiceBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "LogService-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "LogServiceOne" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.entries != "/redfish/v1/LogEntryCollection" {
t.Errorf("Received invalid log entry collection: %s", result.entries)
}
if result.LogEntryType != EventLogEntryTypes {
t.Errorf("Received %s log entry type", result.LogEntryType)
}
if result.MaxNumberOfRecords != 1000 {
t.Errorf("Received %d max number of records", result.MaxNumberOfRecords)
}
if result.OverWritePolicy != WrapsWhenFullOverWritePolicy {
t.Errorf("Received %s overwrite policy", result.OverWritePolicy)
}
if !result.ServiceEnabled {
t.Error("Service should be enabled")
}
if result.clearLogTarget != "/redfish/v1/Managers/BMC/LogServices/Log/Actions/LogService.ClearLog" {
t.Errorf("Invalid ClearLog target: %s", result.clearLogTarget)
}
}
// TestLogServiceUpdate tests the Update call.
func TestLogServiceUpdate(t *testing.T) {
var result LogService
err := json.NewDecoder(strings.NewReader(logServiceBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
result.ServiceEnabled = false
err = result.Update()
if err != nil {
t.Errorf("Error making Update call: %s", err)
}
calls := testClient.CapturedCalls()
if !strings.Contains(calls[0].Payload, "ServiceEnabled:false") {
t.Errorf("Unexpected ServiceEnabled update payload: %s", calls[0].Payload)
}
}