go-cook/internal/services/userService_test.go

49 lines
874 B
Go

package services_test
import (
"testing"
"git.jamestombleson.com/jtom38/go-cook/internal/services"
"github.com/DATA-DOG/go-sqlmock"
)
func TestPasswordIsLongEnough(t *testing.T) {
db, _, err := sqlmock.New()
if err != nil {
t.Log(err.Error())
t.FailNow()
}
defer db.Close()
client := services.NewUserService(db)
err = client.CheckPasswordForRequirements("IsThisLongEnough")
if err != nil {
t.Logf(err.Error())
t.FailNow()
}
}
func TestPasswordIsToShort(t *testing.T) {
db, _, err := sqlmock.New()
if err != nil {
t.Log(err.Error())
t.FailNow()
}
defer db.Close()
client := services.NewUserService(db)
err = client.CheckPasswordForRequirements("short")
if err != nil {
msg := err.Error()
if msg != services.ErrPasswordNotLongEnough {
t.Log("wrong error")
t.FailNow()
}
} else {
t.Logf("expected a err")
t.FailNow()
}
}