-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroups_test.go
204 lines (195 loc) · 4.5 KB
/
groups_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
package hudorbot
import (
"testing"
)
func TestNewGroupSettings(t *testing.T) {
testCases := []struct {
input map[string]string
output groupSettings
}{
{
input: map[string]string{},
output: groupSettings{},
},
{
input: map[string]string{
"isActive": "0",
"showWarn": "0",
"limit": "5",
"creator": "18854411",
"title": "test1",
"description": "desc test1",
},
output: groupSettings{
IsActive: false,
ShowWarn: false,
Limit: 5,
Creator: 18854411,
Title: "test1",
Description: "desc test1",
},
},
{
input: map[string]string{
"isActive": "1",
"showWarn": "1",
"limit": "wrong",
},
output: groupSettings{
IsActive: true,
ShowWarn: true,
Limit: 0,
Creator: 0,
},
},
}
for _, tc := range testCases {
o := newGroupSettings(tc.input)
if o.IsActive != tc.output.IsActive {
t.Errorf("excpected isActive to be %t but receive %t\n", tc.output.IsActive, o.IsActive)
}
if o.ShowWarn != tc.output.ShowWarn {
t.Errorf("excpected ShowWarn to be %t but recieve %t\n", tc.output.ShowWarn, o.ShowWarn)
}
if o.Limit != tc.output.Limit {
t.Errorf("excpected Limit to be %d but receive %d\n", tc.output.Limit, o.Limit)
}
if o.Creator != tc.output.Creator {
t.Errorf("excpected Creator to be %d but receive %d\n", tc.output.Creator, o.Creator)
}
if o.Title != tc.output.Title {
t.Errorf("excpected Title to be %s but receive %s\n", tc.output.Title, o.Title)
}
if o.Description != tc.output.Description {
t.Errorf("excpected Description to be %s but receive %s\n", tc.output.Description, o.Description)
}
}
}
func TestMap(t *testing.T) {
testCases := []struct {
input groupSettings
output map[string]string
}{
{
input: groupSettings{
IsActive: false,
ShowWarn: false,
Limit: 0,
Creator: -10,
Title: "",
Description: "",
},
output: map[string]string{
"isActive": "false",
"showWarn": "false",
"limit": "0",
"creator": "-10",
"title": "",
"description": "",
},
},
{
input: groupSettings{},
output: map[string]string{
"isActive": "false",
"showWarn": "false",
"limit": "0",
"creator": "0",
"title": "",
"description": "",
},
},
{
input: groupSettings{
IsActive: true,
ShowWarn: true,
Limit: 2,
Creator: 189510000,
Title: "test",
Description: "test desc",
},
output: map[string]string{
"isActive": "true",
"showWarn": "true",
"limit": "2",
"creator": "189510000",
"title": "test",
"description": "test desc",
},
},
}
for _, tc := range testCases {
o := tc.input.Map()
if o["isActive"] != tc.output["isActive"] {
t.Errorf("excpected")
}
if o["isActive"] != tc.output["isActive"] {
t.Errorf("excpected isActive to be %s but receive %s\n", tc.output["isActive"], o["isActive"])
}
if o["showWarn"] != tc.output["showWarn"] {
t.Errorf("excpected ShowWarn to be %s but recieve %s\n", tc.output["showWarn"], o["showWarn"])
}
if o["limit"] != tc.output["limit"] {
t.Errorf("excpected Limit to be %s but receive %s\n", tc.output["limit"], o["limit"])
}
if o["creator"] != tc.output["creator"] {
t.Errorf("excpected Creator to be %s but receive %s\n", tc.output["creator"], o["creator"])
}
if o["title"] != tc.output["title"] {
t.Errorf("excpected Title to be %s but receive %s\n", tc.output["title"], o["title"])
}
if o["description"] != tc.output["description"] {
t.Errorf("excpected Description to be %s but receive %s\n", tc.output["description"], o["description"])
}
}
}
func TestWhitelistKey(t *testing.T) {
testCases := []struct {
input int64
output string
}{
{
100000,
"whitelist:100000",
},
{
-100000,
"whitelist:-100000",
},
{
0,
"whitelist:0",
},
}
for _, tc := range testCases {
output := whiteListKey(tc.input)
if output != tc.output {
t.Errorf("excpected whitelist key to be %s but received %s", tc.output, output)
}
}
}
func TestGroupKey(t *testing.T) {
testCases := []struct {
input int64
output string
}{
{
100000,
"group:100000",
},
{
-100000,
"group:-100000",
},
{
0,
"group:0",
},
}
for _, tc := range testCases {
output := groupKey(tc.input)
if output != tc.output {
t.Errorf("excpected group settings key to be %s but received %s", tc.output, output)
}
}
}