New set of Unit Tests for Build, based on 0.4.0
This commit is contained in:
parent
a2ade4a5cc
commit
db02db06f1
1 changed files with 17 additions and 76 deletions
|
@ -8,7 +8,6 @@ import (
|
||||||
|
|
||||||
func TestBuildstore(t *testing.T) {
|
func TestBuildstore(t *testing.T) {
|
||||||
db := mustConnectTest()
|
db := mustConnectTest()
|
||||||
rs := NewRepostore(db)
|
|
||||||
bs := NewBuildstore(db)
|
bs := NewBuildstore(db)
|
||||||
cs := NewCommitstore(db)
|
cs := NewCommitstore(db)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
@ -18,55 +17,22 @@ func TestBuildstore(t *testing.T) {
|
||||||
|
|
||||||
// before each test we purge the package table data from the database.
|
// before each test we purge the package table data from the database.
|
||||||
g.BeforeEach(func() {
|
g.BeforeEach(func() {
|
||||||
db.Exec("DELETE FROM blobs")
|
|
||||||
db.Exec("DELETE FROM builds")
|
db.Exec("DELETE FROM builds")
|
||||||
db.Exec("DELETE FROM commits")
|
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() {
|
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
|
//Add build
|
||||||
build := common.Build{
|
build := common.Build{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
CommitID: 1,
|
CommitID: 1,
|
||||||
State: "success",
|
State: "success",
|
||||||
}
|
}
|
||||||
_err1 = bs.SetBuild(&build)
|
err1 := bs.SetBuild(&build)
|
||||||
g.Assert(_err1 == nil).IsTrue()
|
g.Assert(err1 == nil).IsTrue()
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("Build()", func() {
|
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{
|
build_list := []*common.Build{
|
||||||
&common.Build{
|
&common.Build{
|
||||||
//ID: 1,
|
//ID: 1,
|
||||||
|
@ -95,27 +61,14 @@ func TestBuildstore(t *testing.T) {
|
||||||
Builds: build_list,
|
Builds: build_list,
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
_err1 = cs.AddCommit(&commit1)
|
err1 := cs.AddCommit(&commit1)
|
||||||
g.Assert(_err1 == nil).IsTrue()
|
g.Assert(err1 == nil).IsTrue()
|
||||||
_build, _err := bs.Build(1)
|
build, err2 := bs.Build(1)
|
||||||
g.Assert(_err == nil).IsTrue()
|
g.Assert(err2 == nil).IsTrue()
|
||||||
g.Assert(_build.ID == 1).IsTrue()
|
g.Assert(build.ID == 1).IsTrue()
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("BuildSeq()", func() {
|
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{
|
build_list := []*common.Build{
|
||||||
&common.Build{
|
&common.Build{
|
||||||
CommitID: 1,
|
CommitID: 1,
|
||||||
|
@ -142,27 +95,15 @@ func TestBuildstore(t *testing.T) {
|
||||||
Builds: build_list,
|
Builds: build_list,
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
_err1 = cs.AddCommit(&commit1)
|
err1 := cs.AddCommit(&commit1)
|
||||||
g.Assert(_err1 == nil).IsTrue()
|
g.Assert(err1 == nil).IsTrue()
|
||||||
_build, _err := bs.BuildSeq(&commit1, 2)
|
build, err2 := bs.BuildSeq(&commit1, 2)
|
||||||
g.Assert(_err == nil).IsTrue()
|
g.Assert(err2 == nil).IsTrue()
|
||||||
g.Assert(_build.Sequence == 2).IsTrue()
|
g.Assert(build.Sequence == 2).IsTrue()
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("BuildList()", func() {
|
g.It("BuildList()", func() {
|
||||||
repo := common.Repo{
|
|
||||||
UserID: 1,
|
|
||||||
Owner: "oliveiradan",
|
|
||||||
Name: "drone-test1",
|
|
||||||
}
|
|
||||||
//Add repo
|
//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{
|
build_list := []*common.Build{
|
||||||
&common.Build{
|
&common.Build{
|
||||||
CommitID: 1,
|
CommitID: 1,
|
||||||
|
@ -195,11 +136,11 @@ func TestBuildstore(t *testing.T) {
|
||||||
Builds: build_list,
|
Builds: build_list,
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
_err1 = cs.AddCommit(&commit1)
|
err1 := cs.AddCommit(&commit1)
|
||||||
g.Assert(_err1 == nil).IsTrue()
|
g.Assert(err1 == nil).IsTrue()
|
||||||
_buildList, _err := bs.BuildList(&commit1)
|
buildList, err2 := bs.BuildList(&commit1)
|
||||||
g.Assert(_err == nil).IsTrue()
|
g.Assert(err2 == nil).IsTrue()
|
||||||
g.Assert(len(_buildList)).Equal(3)
|
g.Assert(len(buildList)).Equal(3)
|
||||||
g.Assert(build_list[0].Sequence).Equal(1)
|
g.Assert(build_list[0].Sequence).Equal(1)
|
||||||
g.Assert(build_list[0].State).Equal(common.StateSuccess)
|
g.Assert(build_list[0].State).Equal(common.StateSuccess)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue