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:
parent
db02db06f1
commit
a698810847
@ -1,6 +1,7 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
"github.com/drone/drone/common"
|
||||
"github.com/franela/goblin"
|
||||
"testing"
|
||||
@ -21,55 +22,8 @@ func TestBuildstore(t *testing.T) {
|
||||
db.Exec("DELETE FROM commits")
|
||||
})
|
||||
|
||||
g.It("NewBuildstore()", func() {
|
||||
//Add build
|
||||
build := common.Build{
|
||||
ID: 1,
|
||||
CommitID: 1,
|
||||
State: "success",
|
||||
}
|
||||
err1 := bs.SetBuild(&build)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
})
|
||||
|
||||
g.It("Build()", func() {
|
||||
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, err2 := bs.Build(1)
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(build.ID == 1).IsTrue()
|
||||
})
|
||||
|
||||
g.It("BuildSeq()", func() {
|
||||
build_list := []*common.Build{
|
||||
g.It("Should update an existing build in the datastore", func() {
|
||||
buildList := []*common.Build{
|
||||
&common.Build{
|
||||
CommitID: 1,
|
||||
State: "success",
|
||||
@ -92,19 +46,102 @@ func TestBuildstore(t *testing.T) {
|
||||
State: common.StateSuccess,
|
||||
Ref: "refs/heads/master",
|
||||
Sha: "14710626f22791619d3b7e9ccf58b10374e5b76d",
|
||||
Builds: build_list,
|
||||
Builds: buildList,
|
||||
}
|
||||
//
|
||||
//Add commit, build, retrieve 2nd, update it and recheck it.
|
||||
err1 := cs.AddCommit(&commit1)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
build, err2 := bs.BuildSeq(&commit1, 2)
|
||||
g.Assert(commit1.ID != 0).IsTrue()
|
||||
g.Assert(commit1.Sequence).Equal(1)
|
||||
//
|
||||
build, err2 := bs.Build(commit1.Builds[1].ID)
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(build.Sequence == 2).IsTrue()
|
||||
g.Assert(build.ID).Equal(commit1.Builds[1].ID)
|
||||
build.State = common.StatePending
|
||||
err1 = bs.SetBuild(build)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
build, err2 = bs.Build(commit1.Builds[1].ID)
|
||||
g.Assert(build.ID).Equal(commit1.Builds[1].ID)
|
||||
g.Assert(build.State).Equal(common.StatePending)
|
||||
})
|
||||
|
||||
g.It("BuildList()", func() {
|
||||
g.It("Should return a build by ID", func() {
|
||||
buildList := []*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: buildList,
|
||||
}
|
||||
//Add commit, build, retrieve 2nd build ID.
|
||||
err1 := cs.AddCommit(&commit1)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(commit1.ID != 0).IsTrue()
|
||||
g.Assert(commit1.Sequence).Equal(1)
|
||||
//
|
||||
build, err2 := bs.Build(commit1.Builds[1].ID)
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(build.ID).Equal(commit1.Builds[1].ID)
|
||||
})
|
||||
|
||||
g.It("Should return a build by Sequence", func() {
|
||||
buildList := []*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: buildList,
|
||||
}
|
||||
//Add commit, build, retrieve 2nd build ID.
|
||||
err1 := cs.AddCommit(&commit1)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
g.Assert(commit1.ID != 0).IsTrue()
|
||||
g.Assert(commit1.Sequence).Equal(1)
|
||||
//
|
||||
build, err2 := bs.BuildSeq(&commit1, commit1.Builds[1].Sequence)
|
||||
g.Assert(err2 == nil).IsTrue()
|
||||
g.Assert(build.Sequence).Equal(commit1.Builds[1].Sequence)
|
||||
})
|
||||
|
||||
g.It("Should return a list of all commit builds", func() {
|
||||
//Add repo
|
||||
build_list := []*common.Build{
|
||||
buildList := []*common.Build{
|
||||
&common.Build{
|
||||
CommitID: 1,
|
||||
State: "success",
|
||||
@ -133,16 +170,16 @@ func TestBuildstore(t *testing.T) {
|
||||
State: common.StateSuccess,
|
||||
Ref: "refs/heads/master",
|
||||
Sha: "14710626f22791619d3b7e9ccf58b10374e5b76d",
|
||||
Builds: build_list,
|
||||
Builds: buildList,
|
||||
}
|
||||
//
|
||||
err1 := cs.AddCommit(&commit1)
|
||||
g.Assert(err1 == nil).IsTrue()
|
||||
buildList, err2 := bs.BuildList(&commit1)
|
||||
bldList, 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)
|
||||
g.Assert(len(bldList)).Equal(3)
|
||||
g.Assert(bldList[0].Sequence).Equal(1)
|
||||
g.Assert(bldList[0].State).Equal(common.StateSuccess)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user