-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathalice_test.go
205 lines (198 loc) · 3.52 KB
/
alice_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 alice_test
import (
"context"
"testing"
"github.com/azzzak/alice"
"github.com/stretchr/testify/assert"
)
func TestAutoPong(t *testing.T) {
type args struct {
b bool
}
tests := []struct {
name string
args bool
want alice.Options
}{
{
name: "",
args: true,
want: alice.Options{
AutoPong: true,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
conf := alice.Options{}
opt := alice.AutoPong(tt.args)
opt(&conf)
assert.Equal(t, tt.want, conf)
})
}
}
func TestTimeout(t *testing.T) {
tests := []struct {
name string
args int
want alice.Options
}{
{
name: "",
args: 2500,
want: alice.Options{
Timeout: 2500,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
conf := alice.Options{}
opt := alice.Timeout(tt.args)
opt(&conf)
assert.Equal(t, tt.want, conf)
})
}
}
func TestDebug(t *testing.T) {
tests := []struct {
name string
args bool
want alice.Options
}{
{
name: "",
args: true,
want: alice.Options{
Debug: true,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
conf := alice.Options{}
opt := alice.Debug(tt.args)
opt(&conf)
assert.Equal(t, tt.want, conf)
})
}
}
func TestKit_Init(t *testing.T) {
type fields struct {
Req *alice.Request
Resp *alice.Response
Ctx context.Context
}
tests := []struct {
name string
fields fields
want *alice.Request
want1 *alice.Response
}{
{
name: "",
fields: fields{
Req: getReq(0),
Resp: getResp(0),
},
want: getReq(0),
want1: getResp(0),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
k := alice.Kit{
Req: tt.fields.Req,
Resp: tt.fields.Resp,
}
got, got1 := k.Init()
assert.Equal(t, tt.want, got)
assert.Equal(t, tt.want1, got1)
})
}
}
func TestPlural(t *testing.T) {
type args struct {
n int
singular string
plural1 string
plural2 string
}
tests := []struct {
name string
args args
want string
}{
{
name: "",
args: args{
n: 0,
singular: "бутылка",
plural1: "бутылки",
plural2: "бутылок",
},
want: "бутылок",
}, {
name: "",
args: args{
n: 1,
singular: "бутылка",
plural1: "бутылки",
plural2: "бутылок",
},
want: "бутылка",
}, {
name: "",
args: args{
n: 2,
singular: "бутылка",
plural1: "бутылки",
plural2: "бутылок",
},
want: "бутылки",
}, {
name: "",
args: args{
n: 5,
singular: "бутылка",
plural1: "бутылки",
plural2: "бутылок",
},
want: "бутылок",
}, {
name: "",
args: args{
n: 15,
singular: "бутылка",
plural1: "бутылки",
plural2: "бутылок",
},
want: "бутылок",
}, {
name: "",
args: args{
n: 21,
singular: "бутылка",
plural1: "бутылки",
plural2: "бутылок",
},
want: "бутылка",
}, {
name: "",
args: args{
n: 105,
singular: "бутылка",
plural1: "бутылки",
plural2: "бутылок",
},
want: "бутылок",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := alice.Plural(tt.args.n, tt.args.singular, tt.args.plural1, tt.args.plural2); got != tt.want {
t.Errorf("PluralForm() = %v, want %v", got, tt.want)
}
})
}
}