package services_test import ( "go-cook/api/services" "testing" "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() } }