-
Notifications
You must be signed in to change notification settings - Fork 40
/
validate_test.go
35 lines (29 loc) · 1.04 KB
/
validate_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
package passwordvalidator
import (
"testing"
)
func TestValidate(t *testing.T) {
err := Validate("mypass", 50)
expectedError := "insecure password, try including more special characters, using uppercase letters, using numbers or using a longer password"
if err.Error() != expectedError {
t.Errorf("Wanted %v, got %v", expectedError, err)
}
err = Validate("MYPASS", 50)
expectedError = "insecure password, try including more special characters, using lowercase letters, using numbers or using a longer password"
if err.Error() != expectedError {
t.Errorf("Wanted %v, got %v", expectedError, err)
}
err = Validate("mypassword", 4)
if err != nil {
t.Errorf("Err should be nil")
}
err = Validate("aGoo0dMi#oFChaR2", 80)
if err != nil {
t.Errorf("Err should be nil")
}
expectedError = "insecure password, try including more special characters, using lowercase letters, using uppercase letters or using a longer password"
err = Validate("123", 60)
if err.Error() != expectedError {
t.Errorf("Wanted %v, got %v", expectedError, err)
}
}