-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_test.go
58 lines (54 loc) · 1.04 KB
/
service_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
package railroad
import "testing"
func TestRegister(t *testing.T) {
tests := []struct {
name string
req UserRegistrationRequest
res bool
}{
{
name: "valid request",
req: UserRegistrationRequest{
Username: "dhouston",
Email: "[email protected]",
},
res: true,
},
{
name: "username too long",
req: UserRegistrationRequest{
Username: "dhoustondhouston",
Email: "[email protected]",
},
res: false,
},
{
name: "email wrong format",
req: UserRegistrationRequest{
Username: "dhouston",
Email: "dan",
},
res: false,
},
{
name: "user already exists",
req: UserRegistrationRequest{
Username: "chouston",
Email: "[email protected]",
},
res: false,
},
}
for _, tt := range tests {
test := tt
t.Run(test.name, func(t *testing.T) {
svc := UserService{
db: map[string]UserRegistrationRequest{},
}
res := svc.Register(test.req)
if want, got := test.res, res; want != got {
t.Errorf("Wrong result. Want %v got %v", want, got)
}
})
}
}