Test cleanup and style fixes

- Update Makefile to the latest test syntax.
parent 3efff3ed
......@@ -9,8 +9,12 @@ all:
race:
go build -race -ldflags "-X main.vercommit=$(COMMIT) -X main.vergo=$(VERGO)"
# -count 1 is the idiomatic way to disable test caching in package list mode
test:
go test -race
go test -count 1 -cover
testrace:
go test -count 1 -cover -race
clean:
go clean
......@@ -2,25 +2,25 @@ package main
import "testing"
func DefaultJob() Job {
uid := "00000000-0000-9000-0000-000000000000"
func defaultJob() Job {
uid := "job1"
return Job{UserID: &uid}
}
func TestJobsValidateMissingUserId(t *testing.T) {
j := DefaultJob()
j.UserID = nil
func TestValidateJob(t *testing.T) {
j := defaultJob()
if err := j.Validate(); err != nil && err.Error() != jobReqUserID {
t.Errorf("\nRan: Job.Validate(%#v)\nExpected: %v\nGot: %v", j,
jobReqUserID, err.Error())
if err := j.Validate(); err != nil {
t.Errorf("\nRan: Job.Validate(%#v)\nExpected: %#v\nGot: %#v", j, nil, err)
}
}
func TestJobsValidatePassing(t *testing.T) {
j := DefaultJob()
func TestValidateJobReqUserID(t *testing.T) {
j := defaultJob()
j.UserID = nil
if err := j.Validate(); err != nil {
t.Errorf("\nRan: Job.Validate(%#v)\nExpected: %v\nGot: %v", j, nil, err.Error())
if err := j.Validate(); err != nil && err.Error() != jobReqUserID {
t.Errorf("\nRan: Job.Validate(%#v)\nExpected: %#v\nGot: %#v", j,
jobReqUserID, err)
}
}
......@@ -2,93 +2,93 @@ package main
import "testing"
func DefaultUser() User {
func defaultUser() User {
ut := "user"
return User{UserType: &ut, FirstName: "First", LastName: "Last",
Email: "email@example.com", Login: "flast", BcryptHash: "$2a$10$..."}
}
func DefaultUserWithPass() User {
func defaultUserWithPass() User {
ut := "user"
pass := "mypass"
return User{UserType: &ut, FirstName: "First", LastName: "Last",
Email: "email@example.com", Login: "flast", Password: &pass}
}
func TestUsersValidateMissingUserTypeId(t *testing.T) {
u := DefaultUser()
func TestValidateUser(t *testing.T) {
u := defaultUser()
if err := u.Validate(); err != nil {
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %#v\nGot: %#v", u, nil,
err)
}
}
func TestValidateUserPass(t *testing.T) {
u := defaultUserWithPass()
if err := u.Validate(); err != nil {
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %#v\nGot: %#v", u, nil,
err)
}
}
func TestValidateUserReqUserTypeID(t *testing.T) {
u := defaultUser()
u.UserType = nil
if err := u.Validate(); err != nil && err.Error() != userReqUserTypeID {
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %v\nGot: %v", u,
userReqUserTypeID, err.Error())
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %#v\nGot: %#v", u,
userReqUserTypeID, err)
}
}
func TestUsersValidateMissingFirstName(t *testing.T) {
u := DefaultUser()
func TestValidateUserReqFirstName(t *testing.T) {
u := defaultUser()
u.FirstName = ""
if err := u.Validate(); err != nil && err.Error() != userReqFirstName {
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %v\nGot: %v", u,
userReqFirstName, err.Error())
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %#v\nGot: %#v", u,
userReqFirstName, err)
}
}
func TestUsersValidateMissingLastName(t *testing.T) {
u := DefaultUser()
func TestValidateUserReqLastName(t *testing.T) {
u := defaultUser()
u.LastName = ""
if err := u.Validate(); err != nil && err.Error() != userReqLastName {
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %v\nGot: %v", u,
userReqLastName, err.Error())
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %#v\nGot: %#v", u,
userReqLastName, err)
}
}
func TestUsersValidateMissingEmail(t *testing.T) {
u := DefaultUser()
func TestValidateUserReqEmail(t *testing.T) {
u := defaultUser()
u.Email = ""
if err := u.Validate(); err != nil && err.Error() != userReqEmail {
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %v\nGot: %v", u,
userReqEmail, err.Error())
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %#v\nGot: %#v", u,
userReqEmail, err)
}
}
func TestUsersValidateMissingLogin(t *testing.T) {
u := DefaultUser()
func TestValidateUserReqLogin(t *testing.T) {
u := defaultUser()
u.Login = ""
if err := u.Validate(); err != nil && err.Error() != userReqLogin {
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %v\nGot: %v", u,
userReqLogin, err.Error())
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %#v\nGot: %#v", u,
userReqLogin, err)
}
}
func TestUsersValidateMissingPasswordBcrypt(t *testing.T) {
u := DefaultUser()
func TestValidateUserReqPassword(t *testing.T) {
u := defaultUser()
u.BcryptHash = ""
if err := u.Validate(); err != nil && err.Error() != userReqPassword {
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %v\nGot: %v", u,
userReqPassword, err.Error())
}
}
func TestUsersValidatePassingPassword(t *testing.T) {
u := DefaultUserWithPass()
if err := u.Validate(); err != nil {
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %v\nGot: %v", u, nil,
err.Error())
}
}
func TestUsersValidatePassingBcrypt(t *testing.T) {
u := DefaultUser()
if err := u.Validate(); err != nil {
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %v\nGot: %v", u, nil,
err.Error())
t.Errorf("\nRan: User.Validate(%#v)\nExpected: %#v\nGot: %#v", u,
userReqPassword, err)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment