1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-30 08:06:52 +02:00

New set of Unit Tests for Build, based on 0.4.0

This commit is contained in:
Daniel Oliveira 2015-05-14 11:52:45 -06:00
parent 1ef6dc0bc6
commit a2ade4a5cc

View File

@ -0,0 +1,207 @@
package builtin
import (
"github.com/drone/drone/common"
"github.com/franela/goblin"
"testing"
)
func TestBuildstore(t *testing.T) {
db := mustConnectTest()
rs := NewRepostore(db)
bs := NewBuildstore(db)
cs := NewCommitstore(db)
defer db.Close()
g := goblin.Goblin(t)
g.Describe("Buildstore", func() {
// before each test we purge the package table data from the database.
g.BeforeEach(func() {
db.Exec("DELETE FROM blobs")
db.Exec("DELETE FROM builds")
db.Exec("DELETE FROM commits")
db.Exec("DELETE FROM repos")
db.Exec("DELETE FROM stars")
db.Exec("DELETE FROM tasks")
db.Exec("DELETE FROM tokens")
db.Exec("DELETE FROM users")
})
g.It("NewBuildstore()", func() {
repo := common.Repo{
UserID: 1,
Owner: "oliveiradan",
Name: "drone-test1",
}
//Add repo
_err1 := rs.AddRepo(&repo)
_err2 := rs.SetRepo(&repo)
getrepo, _err3 := rs.Repo(repo.ID)
g.Assert(_err1 == nil).IsTrue()
g.Assert(_err2 == nil).IsTrue()
g.Assert(_err3 == nil).IsTrue()
g.Assert(repo.ID).Equal(getrepo.ID)
//Add build
build := common.Build{
ID: 1,
CommitID: 1,
State: "success",
}
_err1 = bs.SetBuild(&build)
g.Assert(_err1 == nil).IsTrue()
})
g.It("Build()", func() {
repo := common.Repo{
UserID: 1,
Owner: "oliveiradan",
Name: "drone-test1",
}
//Add repo
_err1 := rs.AddRepo(&repo)
_err2 := rs.SetRepo(&repo)
getrepo, _err3 := rs.Repo(repo.ID)
g.Assert(_err1 == nil).IsTrue()
g.Assert(_err2 == nil).IsTrue()
g.Assert(_err3 == nil).IsTrue()
g.Assert(repo.ID).Equal(getrepo.ID)
build_list := []*common.Build{
&common.Build{
//ID: 1,
CommitID: 1,
State: "success",
ExitCode: 0,
Sequence: 1,
},
&common.Build{
//ID: 2,
CommitID: 3,
State: "error",
ExitCode: 1,
Sequence: 2,
},
}
//In order for buid to be populated,
//The AddCommit command will insert builds
//if the Commit.Builds array is populated
//Add Commit.
commit1 := common.Commit{
RepoID: 1,
State: common.StateSuccess,
Ref: "refs/heads/master",
Sha: "14710626f22791619d3b7e9ccf58b10374e5b76d",
Builds: build_list,
}
//
_err1 = cs.AddCommit(&commit1)
g.Assert(_err1 == nil).IsTrue()
_build, _err := bs.Build(1)
g.Assert(_err == nil).IsTrue()
g.Assert(_build.ID == 1).IsTrue()
})
g.It("BuildSeq()", func() {
repo := common.Repo{
UserID: 1,
Owner: "oliveiradan",
Name: "drone-test1",
}
//Add repo
_err1 := rs.AddRepo(&repo)
_err2 := rs.SetRepo(&repo)
getrepo, _err3 := rs.Repo(repo.ID)
g.Assert(_err1 == nil).IsTrue()
g.Assert(_err2 == nil).IsTrue()
g.Assert(_err3 == nil).IsTrue()
g.Assert(repo.ID).Equal(getrepo.ID)
build_list := []*common.Build{
&common.Build{
CommitID: 1,
State: "success",
ExitCode: 0,
Sequence: 1,
},
&common.Build{
CommitID: 3,
State: "error",
ExitCode: 1,
Sequence: 2,
},
}
//In order for buid to be populated,
//The AddCommit command will insert builds
//if the Commit.Builds array is populated
//Add Commit.
commit1 := common.Commit{
RepoID: 1,
State: common.StateSuccess,
Ref: "refs/heads/master",
Sha: "14710626f22791619d3b7e9ccf58b10374e5b76d",
Builds: build_list,
}
//
_err1 = cs.AddCommit(&commit1)
g.Assert(_err1 == nil).IsTrue()
_build, _err := bs.BuildSeq(&commit1, 2)
g.Assert(_err == nil).IsTrue()
g.Assert(_build.Sequence == 2).IsTrue()
})
g.It("BuildList()", func() {
repo := common.Repo{
UserID: 1,
Owner: "oliveiradan",
Name: "drone-test1",
}
//Add repo
_err1 := rs.AddRepo(&repo)
_err2 := rs.SetRepo(&repo)
getrepo, _err3 := rs.Repo(repo.ID)
g.Assert(_err1 == nil).IsTrue()
g.Assert(_err2 == nil).IsTrue()
g.Assert(_err3 == nil).IsTrue()
g.Assert(repo.ID).Equal(getrepo.ID)
build_list := []*common.Build{
&common.Build{
CommitID: 1,
State: "success",
ExitCode: 0,
Sequence: 1,
},
&common.Build{
CommitID: 3,
State: "error",
ExitCode: 1,
Sequence: 2,
},
&common.Build{
CommitID: 5,
State: "pending",
ExitCode: 0,
Sequence: 3,
},
}
//In order for buid to be populated,
//The AddCommit command will insert builds
//if the Commit.Builds array is populated
//Add Commit.
commit1 := common.Commit{
RepoID: 1,
State: common.StateSuccess,
Ref: "refs/heads/master",
Sha: "14710626f22791619d3b7e9ccf58b10374e5b76d",
Builds: build_list,
}
//
_err1 = cs.AddCommit(&commit1)
g.Assert(_err1 == nil).IsTrue()
_buildList, _err := bs.BuildList(&commit1)
g.Assert(_err == nil).IsTrue()
g.Assert(len(_buildList)).Equal(3)
g.Assert(build_list[0].Sequence).Equal(1)
g.Assert(build_list[0].State).Equal(common.StateSuccess)
})
})
}