Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed May 23, 2017
1 parent 3f45889 commit 08b320e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
14 changes: 8 additions & 6 deletions store/datastore/builds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ func TestBuilds(t *testing.T) {
Name: "drone",
}

db := openTest()
defer db.Close()
s := newTest()
defer s.Close()

s := From(db)
g := goblin.Goblin(t)
g.Describe("Builds", func() {
g.Before(func() {
db.Exec("DELETE FROM repos")
s.Exec("DELETE FROM repos")
s.CreateRepo(repo)
})
g.After(func() {
s.Exec("DELETE FROM repos")
})

// before each test be sure to purge the package
// table data from the database.
g.BeforeEach(func() {
db.Exec("DELETE FROM builds")
db.Exec("DELETE FROM jobs")
s.Exec("DELETE FROM builds")
s.Exec("DELETE FROM jobs")
})

g.It("Should Post a Build", func() {
Expand Down
23 changes: 13 additions & 10 deletions store/datastore/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,23 @@ func TestConfigApproved(t *testing.T) {
defer func() {
s.Exec("delete from config")
s.Exec("delete from builds")
s.Exec("delete from repos")
s.Close()
}()

repo := &model.Repo{
UserID: 1,
FullName: "bradrydzewski/drone",
Owner: "bradrydzewski",
Name: "drone",
}
s.CreateRepo(repo)

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

s.CreateBuild(&model.Build{
RepoID: 1,
RepoID: repo.ID,
ConfigID: conf.ID,
Status: model.StatusRunning,
Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac",
Expand Down
19 changes: 11 additions & 8 deletions store/datastore/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ import (
)

func TestUsers(t *testing.T) {
db := openTest()
defer db.Close()
s := From(db)
s := newTest()
defer s.Close()

g := goblin.Goblin(t)
g.Describe("User", func() {

// before each test be sure to purge the package
// table data from the database.
g.BeforeEach(func() {
db.Exec("DELETE FROM users")
db.Exec("DELETE FROM repos")
db.Exec("DELETE FROM builds")
db.Exec("DELETE FROM jobs")
s.Exec("DELETE FROM users")
s.Exec("DELETE FROM repos")
s.Exec("DELETE FROM builds")
s.Exec("DELETE FROM jobs")
})

g.It("Should Update a User", func() {
Expand Down Expand Up @@ -138,7 +137,11 @@ func TestUsers(t *testing.T) {
s.CreateUser(&user2)
count, err := s.GetUserCount()
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() {
Expand Down

0 comments on commit 08b320e

Please sign in to comment.