go-sample-webpage/pkg/user/userclient_test.go
kekskurse 7b6204a0b3
All checks were successful
continuous-integration/drone/push Build is passing
Uer Config
2021-11-09 19:23:19 +01:00

59 lines
No EOL
1.1 KiB
Go

package user
import (
"testing"
)
func TestAdminUserExists(t *testing.T) {
u := GetUserClient()
res, err := u.login("admin", "password")
if err != nil {
t.Error("Login should not return a error")
}
if res == false {
t.Error("Login should return true for admin/password")
} else {
t.Log("Login for admin/password works")
}
}
func TestLoginWithWrongUserDataFailed(t *testing.T) {
u := GetUserClient()
res, err := u.login("invalide", "data")
if err != nil {
t.Error("Login shouldnt return an erroro")
}
if res == true {
t.Error("Login shouldnt be true with invalide data")
} else {
t.Log("Login failed successfully")
}
}
func TestRegisterAndLogin(t *testing.T) {
u := GetUserClient()
res, err := u.register("test", "test", "test@example.com")
if err != nil {
t.Error("Register should not return an error")
}
if res == false {
t.Error("Register schould return true")
} else {
t.Log("User Register ok")
}
res, err = u.login("test", "test")
if err != nil {
t.Error("Login should not return an error")
}
if res == false {
t.Error("Login schould return true")
} else {
t.Log("User Login ok")
}
}