forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanageraccount_test.go
100 lines (80 loc) · 2.42 KB
/
manageraccount_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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var managerAccountBody = `{
"@odata.context": "/redfish/v1/$metadata#AccountService/Links/Members/Accounts/Links/Members/$entity",
"@odata.id": "/redfish/v1/AccountService/Accounts/1",
"@odata.type": "#AccountService.0.94.0.ManagerAccount",
"Id": "1",
"Name": "User Account",
"Modified": "2013-09-11T17:03:55+00:00",
"Description": "User Account",
"Password": null,
"UserName": "Administrator",
"Locked": false,
"Enabled": true,
"RoleId": "Admin",
"Links": {
"Role": {
"@odata.id": "/redfish/v1/AccountService/Roles/Admin"
}
}
}`
// TestAccount tests the parsing of Account objects.
func TestManagerAccount(t *testing.T) {
var result ManagerAccount
err := json.NewDecoder(strings.NewReader(managerAccountBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "User Account" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.RoleID != "Admin" {
t.Errorf("Received invalid Role ID: %s", result.RoleID)
}
if result.role != "/redfish/v1/AccountService/Roles/Admin" {
t.Errorf("Received invalid Role: %s", result.role)
}
}
// TestAccountUpdate tests the Update call.
func TestManagerAccountUpdate(t *testing.T) {
var result ManagerAccount
err := json.NewDecoder(strings.NewReader(managerAccountBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
result.Enabled = false
result.Locked = false
result.Password = "Test"
result.RoleID = "Administrator"
err = result.Update()
if err != nil {
t.Errorf("Error making Update call: %s", err)
}
calls := testClient.CapturedCalls()
if !strings.Contains(calls[0].Payload, "Enabled:false") {
t.Errorf("Unexpected Enabled update payload: %s", calls[0].Payload)
}
if strings.Contains(calls[0].Payload, "Locked") {
t.Errorf("Unexpected Locked in update payload: %s", calls[0].Payload)
}
if !strings.Contains(calls[0].Payload, "Password:Test") {
t.Errorf("Unexpected Password update payload: %s", calls[0].Payload)
}
if !strings.Contains(calls[0].Payload, "RoleId:Administrator") {
t.Errorf("Unexpected Role ID update payload: %s", calls[0].Payload)
}
}