27 lines
680 B
Go
27 lines
680 B
Go
package service
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidatePassword(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
value string
|
|
wantErr bool
|
|
}{
|
|
{name: "lowercase accepted", value: "chengma", wantErr: false},
|
|
{name: "six characters accepted", value: "abcdef", wantErr: false},
|
|
{name: "too short", value: "abcde", wantErr: true},
|
|
{name: "bcrypt byte limit", value: strings.Repeat("a", MaxPasswordBytes+1), wantErr: true},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := ValidatePassword(tt.value); (got != nil) != tt.wantErr {
|
|
t.Fatalf("ValidatePassword() error = %v, wantErr %v", got, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|