commento/api/owner_get_test.go
Adhityaa a090770b73 api: Add go files
I know this is a huge commit, but I can't be bothered to check
this in part by part.
2018-05-27 23:40:46 +05:30

60 lines
1.4 KiB
Go

package main
import (
"testing"
)
func TestOwnerGetByEmailBasics(t *testing.T) {
failTestOnError(t, setupTestEnv())
ownerHex, _ := ownerNew("test@example.com", "Test", "hunter2")
o, err := ownerGetByEmail("test@example.com")
if err != nil {
t.Errorf("unexpected error on ownerGetByEmail: %v", err)
return
}
if o.OwnerHex != ownerHex {
t.Errorf("expected ownerHex=%s got ownerHex=%s", ownerHex, o.OwnerHex)
return
}
}
func TestOwnerGetByEmailDNE(t *testing.T) {
failTestOnError(t, setupTestEnv())
if _, err := ownerGetByEmail("invalid@example.com"); err == nil {
t.Errorf("expected error not found on ownerGetByEmail before creating an account")
return
}
}
func TestOwnerGetBySessionBasics(t *testing.T) {
failTestOnError(t, setupTestEnv())
ownerHex, _ := ownerNew("test@example.com", "Test", "hunter2")
session, _ := ownerLogin("test@example.com", "hunter2")
o, err := ownerGetBySession(session)
if err != nil {
t.Errorf("unexpected error on ownerGetBySession: %v", err)
return
}
if o.OwnerHex != ownerHex {
t.Errorf("expected ownerHex=%s got ownerHex=%s", ownerHex, o.OwnerHex)
return
}
}
func TestOwnerGetBySessionDNE(t *testing.T) {
failTestOnError(t, setupTestEnv())
if _, err := ownerGetBySession("does-not-exist"); err == nil {
t.Errorf("expected error not found on ownerGetBySession before creating an account")
return
}
}