go-cook/internal/services/userService_test.go

49 lines
874 B
Go
Raw Permalink Normal View History

package services_test
import (
"testing"
"git.jamestombleson.com/jtom38/go-cook/internal/services"
2024-04-05 17:51:21 -07:00
"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()
}
}
2024-04-05 17:51:21 -07:00
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()
2024-04-05 17:51:21 -07:00
if msg != services.ErrPasswordNotLongEnough {
t.Log("wrong error")
t.FailNow()
}
2024-04-05 17:51:21 -07:00
} else {
t.Logf("expected a err")
t.FailNow()
}
}