-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth_test.go
62 lines (52 loc) · 1.19 KB
/
auth_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
package xclone
import (
"testing"
)
func TestRegisterInput_Sanitize(t *testing.T) {
input := RegisterInput{
Username: " xxx ",
Email: " [email protected] ",
Password: "password",
ConfirmPassword: "password",
}
want := RegisterInput{
Username: "xxx",
Email: "[email protected]",
Password: "password",
ConfirmPassword: "password",
}
input.Sanitize()
if input != want {
t.Errorf("Sanitize() = %v, want %v", input, want)
}
}
func TestRegisterInput_Validate(t *testing.T) {
testCases := []struct {
name string
input RegisterInput
err error
}{
{
name: "valid",
input: RegisterInput{
Username: "xxx",
Email: "[email protected]",
Password: "password",
ConfirmPassword: "password",
},
err: nil,
},
// Other test cases...
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := tc.input.Validate()
if tc.err != nil && err == nil {
t.Errorf("Validate() expected error %v, got nil", tc.err)
} else if tc.err == nil && err != nil {
t.Errorf("Validate() expected no error, got %v", err)
}
})
}
}
// Similar changes for other test functions...