mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-27 19:00:35 +00:00
update unit tests
This commit is contained in:
parent
3f45889ead
commit
08b320e365
3 changed files with 32 additions and 24 deletions
|
@ -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() {
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
|
|
@ -8,9 +8,8 @@ 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() {
|
||||
|
@ -18,10 +17,10 @@ func TestUsers(t *testing.T) {
|
|||
// 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() {
|
||||
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue