-
Notifications
You must be signed in to change notification settings - Fork 13
/
user_test.go
205 lines (191 loc) · 4.67 KB
/
user_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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package goscaleio
import (
"errors"
"math"
"net/http"
"net/http/httptest"
"testing"
types "github.com/dell/goscaleio/types/v1"
)
func TestCreateUser(t *testing.T) {
type testCase struct {
user types.UserParam
expected error
}
cases := []testCase{
{
user: types.UserParam{
Name: "testUser",
UserRole: "Monitor",
Password: "default",
},
expected: nil,
},
{
user: types.UserParam{
Name: "newUser",
UserRole: "Role",
Password: "password",
},
expected: errors.New("userRole should get on Monitor, Configure, Administrator, Security, FrontendConfig, BackendConfig, but its value is Role"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()
for _, tc := range cases {
tc := tc
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
}
s := System{
client: client,
}
_, err2 := s.CreateUser(&tc.user)
if err2 != nil {
if tc.expected == nil {
t.Errorf("Creating User did not work as expected, \n\tgot: %s \n\twant: %v", err2, tc.expected)
} else {
if err2.Error() != tc.expected.Error() {
t.Errorf("Creating User did not work as expected, \n\tgot: %s \n\twant: %s", err2, tc.expected)
}
}
}
})
}
}
func TestGetUserByIDName(t *testing.T) {
type testCase struct {
id string
name string
expected error
}
cases := []testCase{
{
id: "eeb2dec800000001",
name: "",
expected: nil,
},
{
id: "",
name: "",
expected: errors.New("user name or ID is mandatory, please enter a valid value"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()
for _, tc := range cases {
tc := tc
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
}
s := System{
client: client,
}
_, err2 := s.GetUserByIDName(tc.id, tc.name)
if err2 != nil {
if tc.expected == nil {
t.Errorf("Creating User did not work as expected, \n\tgot: %s \n\twant: %v", err2, tc.expected)
} else {
if err2.Error() != tc.expected.Error() {
t.Errorf("Creating User did not work as expected, \n\tgot: %s \n\twant: %s", err2, tc.expected)
}
}
}
})
}
}
func TestRemoveUser(t *testing.T) {
type testCase struct {
id string
expected error
}
cases := []testCase{
{
id: "eeb2dec800000001",
expected: nil,
},
{
id: "eeb2dec800000005",
expected: errors.New("User not found. Please check that you have the correct user name"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()
for _, tc := range cases {
tc := tc
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
}
s := System{
client: client,
}
err2 := s.RemoveUser(tc.id)
if err2 != nil {
if tc.expected == nil {
t.Errorf("Removing User did not work as expected, \n\tgot: %s \n\twant: %v", err2, tc.expected)
} else {
if err2.Error() != tc.expected.Error() {
t.Errorf("Removing User did not work as expected, \n\tgot: %s \n\twant: %s", err2, tc.expected)
}
}
}
})
}
}
func TestSetRole(t *testing.T) {
type testCase struct {
role types.UserRoleParam
id string
expected error
}
cases := []testCase{
{
role: types.UserRoleParam{
UserRole: "Monitor",
},
id: "eeb2dec800000001",
expected: nil,
},
{
role: types.UserRoleParam{
UserRole: "any",
},
id: "eeb2dec800000001",
expected: errors.New("userRole should get one of the following values: Monitor, Configure, Administrator, Security, FrontendConfig, BackendConfig, but its value is any"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()
for _, tc := range cases {
tc := tc
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
}
s := System{
client: client,
}
err2 := s.SetUserRole(&tc.role, tc.id)
if err2 != nil {
if tc.expected == nil {
t.Errorf("Removing User did not work as expected, \n\tgot: %s \n\twant: %v", err2, tc.expected)
} else {
if err2.Error() != tc.expected.Error() {
t.Errorf("Removing User did not work as expected, \n\tgot: %s \n\twant: %s", err2, tc.expected)
}
}
}
})
}
}