2017-07-17 04:01:35 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestUserValidate(t *testing.T) {
|
|
|
|
var tests = []struct {
|
|
|
|
user User
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
user: User{},
|
|
|
|
err: errUserLoginInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
user: User{Login: "octocat!"},
|
|
|
|
err: errUserLoginInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
user: User{Login: "!octocat"},
|
|
|
|
err: errUserLoginInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
user: User{Login: "john$smith"},
|
|
|
|
err: errUserLoginInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
user: User{Login: "octocat"},
|
|
|
|
err: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
user: User{Login: "john-smith"},
|
|
|
|
err: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
user: User{Login: "john_smith"},
|
|
|
|
err: nil,
|
|
|
|
},
|
2017-10-05 21:02:23 +00:00
|
|
|
{
|
|
|
|
user: User{Login: "john.smith"},
|
|
|
|
err: nil,
|
|
|
|
},
|
2017-07-17 04:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
err := test.user.Validate()
|
|
|
|
if want, got := test.err, err; want != got {
|
|
|
|
t.Errorf("Want user validation error %s, got %s", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|