New set of Unit Tests for Build, based on 0.4.0

This commit is contained in:
Daniel Oliveira 2015-05-14 12:24:32 -06:00
parent a2ade4a5cc
commit db02db06f1

View file

@ -8,7 +8,6 @@ import (
func TestBuildstore(t *testing.T) {
db := mustConnectTest()
rs := NewRepostore(db)
bs := NewBuildstore(db)
cs := NewCommitstore(db)
defer db.Close()
@ -18,55 +17,22 @@ func TestBuildstore(t *testing.T) {
// 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()
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,
@ -95,27 +61,14 @@ func TestBuildstore(t *testing.T) {
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()
err1 := cs.AddCommit(&commit1)
g.Assert(err1 == nil).IsTrue()
build, err2 := bs.Build(1)
g.Assert(err2 == 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,
@ -142,27 +95,15 @@ func TestBuildstore(t *testing.T) {
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()
err1 := cs.AddCommit(&commit1)
g.Assert(err1 == nil).IsTrue()
build, err2 := bs.BuildSeq(&commit1, 2)
g.Assert(err2 == 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,
@ -195,11 +136,11 @@ func TestBuildstore(t *testing.T) {
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)
err1 := cs.AddCommit(&commit1)
g.Assert(err1 == nil).IsTrue()
buildList, err2 := bs.BuildList(&commit1)
g.Assert(err2 == 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)
})