Mainflux.mainflux/users/users_test.go

39 lines
897 B
Go
Raw Normal View History

//
// Copyright (c) 2018
// Mainflux
//
// SPDX-License-Identifier: Apache-2.0
//
2018-05-11 05:53:25 +08:00
package users_test
import (
"fmt"
"testing"
"github.com/mainflux/mainflux/users"
"github.com/stretchr/testify/assert"
)
2018-05-11 07:00:10 +08:00
const (
email = "user@example.com"
password = "password"
)
2018-05-11 05:53:25 +08:00
2018-05-11 07:00:10 +08:00
func TestValidate(t *testing.T) {
2018-05-11 05:53:25 +08:00
cases := map[string]struct {
user users.User
err error
}{
2018-05-11 07:00:10 +08:00
"validate user with valid data": {users.User{email, password}, nil},
"validate user with empty email": {users.User{"", password}, users.ErrMalformedEntity},
"validate user with empty password": {users.User{email, ""}, users.ErrMalformedEntity},
"validate user with invalid email": {users.User{"userexample.com", password}, users.ErrMalformedEntity},
2018-05-11 05:53:25 +08:00
}
for desc, tc := range cases {
2018-05-11 07:00:10 +08:00
err := tc.user.Validate()
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s", desc, tc.err, err))
2018-05-11 05:53:25 +08:00
}
}