update unit tests

This commit is contained in:
Brad Rydzewski 2017-05-23 17:53:40 +02:00
parent 3f45889ead
commit 08b320e365
3 changed files with 32 additions and 24 deletions

View file

@ -15,22 +15,24 @@ func TestBuilds(t *testing.T) {
Name: "drone", Name: "drone",
} }
db := openTest() s := newTest()
defer db.Close() defer s.Close()
s := From(db)
g := goblin.Goblin(t) g := goblin.Goblin(t)
g.Describe("Builds", func() { g.Describe("Builds", func() {
g.Before(func() { g.Before(func() {
db.Exec("DELETE FROM repos") s.Exec("DELETE FROM repos")
s.CreateRepo(repo) s.CreateRepo(repo)
}) })
g.After(func() {
s.Exec("DELETE FROM repos")
})
// before each test be sure to purge the package // before each test be sure to purge the package
// table data from the database. // table data from the database.
g.BeforeEach(func() { g.BeforeEach(func() {
db.Exec("DELETE FROM builds") s.Exec("DELETE FROM builds")
db.Exec("DELETE FROM jobs") s.Exec("DELETE FROM jobs")
}) })
g.It("Should Post a Build", func() { g.It("Should Post a Build", func() {

View file

@ -62,14 +62,23 @@ func TestConfigApproved(t *testing.T) {
defer func() { defer func() {
s.Exec("delete from config") s.Exec("delete from config")
s.Exec("delete from builds") s.Exec("delete from builds")
s.Exec("delete from repos")
s.Close() s.Close()
}() }()
repo := &model.Repo{
UserID: 1,
FullName: "bradrydzewski/drone",
Owner: "bradrydzewski",
Name: "drone",
}
s.CreateRepo(repo)
var ( var (
data = "pipeline: [ { image: golang, commands: [ go build, go test ] } ]" data = "pipeline: [ { image: golang, commands: [ go build, go test ] } ]"
hash = "8d8647c9aa90d893bfb79dddbe901f03e258588121e5202632f8ae5738590b26" hash = "8d8647c9aa90d893bfb79dddbe901f03e258588121e5202632f8ae5738590b26"
conf = &model.Config{ conf = &model.Config{
RepoID: 1, RepoID: repo.ID,
Data: data, Data: data,
Hash: hash, Hash: hash,
} }
@ -79,20 +88,14 @@ func TestConfigApproved(t *testing.T) {
t.Errorf("Unexpected error: insert config: %s", err) t.Errorf("Unexpected error: insert config: %s", err)
return return
} }
s.CreateRepo(&model.Repo{
UserID: 1,
FullName: "bradrydzewski/drone",
Owner: "bradrydzewski",
Name: "drone",
})
s.CreateBuild(&model.Build{ s.CreateBuild(&model.Build{
RepoID: 1, RepoID: repo.ID,
ConfigID: conf.ID, ConfigID: conf.ID,
Status: model.StatusBlocked, Status: model.StatusBlocked,
Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac", Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac",
}) })
s.CreateBuild(&model.Build{ s.CreateBuild(&model.Build{
RepoID: 1, RepoID: repo.ID,
ConfigID: conf.ID, ConfigID: conf.ID,
Status: model.StatusPending, Status: model.StatusPending,
Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac", Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac",
@ -104,7 +107,7 @@ func TestConfigApproved(t *testing.T) {
} }
s.CreateBuild(&model.Build{ s.CreateBuild(&model.Build{
RepoID: 1, RepoID: repo.ID,
ConfigID: conf.ID, ConfigID: conf.ID,
Status: model.StatusRunning, Status: model.StatusRunning,
Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac", Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac",

View file

@ -8,9 +8,8 @@ import (
) )
func TestUsers(t *testing.T) { func TestUsers(t *testing.T) {
db := openTest() s := newTest()
defer db.Close() defer s.Close()
s := From(db)
g := goblin.Goblin(t) g := goblin.Goblin(t)
g.Describe("User", func() { g.Describe("User", func() {
@ -18,10 +17,10 @@ func TestUsers(t *testing.T) {
// before each test be sure to purge the package // before each test be sure to purge the package
// table data from the database. // table data from the database.
g.BeforeEach(func() { g.BeforeEach(func() {
db.Exec("DELETE FROM users") s.Exec("DELETE FROM users")
db.Exec("DELETE FROM repos") s.Exec("DELETE FROM repos")
db.Exec("DELETE FROM builds") s.Exec("DELETE FROM builds")
db.Exec("DELETE FROM jobs") s.Exec("DELETE FROM jobs")
}) })
g.It("Should Update a User", func() { g.It("Should Update a User", func() {
@ -138,7 +137,11 @@ func TestUsers(t *testing.T) {
s.CreateUser(&user2) s.CreateUser(&user2)
count, err := s.GetUserCount() count, err := s.GetUserCount()
g.Assert(err == nil).IsTrue() g.Assert(err == nil).IsTrue()
g.Assert(count).Equal(2) if s.driver != "postgres" {
// we have to skip this check for postgres because it uses
// an estimate which may not be updated.
g.Assert(count).Equal(2)
}
}) })
g.It("Should Get a User Count Zero", func() { g.It("Should Get a User Count Zero", func() {