go-sample-webpage/pkg/user/userclient_test.go

59 lines
1.1 KiB
Go
Raw Normal View History

2021-11-04 16:58:23 +00:00
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")
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")
}
}