About this commit:
1. server/builds.go:92 uses SetStatus(). 2. The other APIs we talked about: Status(), StatusList(), we were able to move out. 3. The repo_del_test.go code merge into repo_test.go 4. Unit tests for the other build APIs added. - We are facing a crash in: github.com/drone/drone/datastore/bolt.(*DB).SetBuildTask(0xc208056080, 0x5e15d0, 0x15, 0x1, 0xc208036940, 0x0, 0x0) which seems to be related to the note in: build.go:207 (// TODO check index to prevent nil pointer / panic) 5. With these new tests we get over 86% plus test cover for bolt package.
This commit is contained in:
parent
6d5255aa75
commit
d13c1caebf
5 changed files with 111 additions and 71 deletions
|
@ -1,7 +1,7 @@
|
|||
package bolt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
//"bytes"
|
||||
"encoding/binary"
|
||||
"strconv"
|
||||
"time"
|
||||
|
@ -114,6 +114,7 @@ func (db *DB) SetBuild(repo string, build *common.Build) error {
|
|||
})
|
||||
}
|
||||
|
||||
/*
|
||||
// Status returns the status for the given repository
|
||||
// and build number.
|
||||
func (db *DB) Status(repo string, build int, status string) (*common.Status, error) {
|
||||
|
@ -147,7 +148,7 @@ func (db *DB) StatusList(repo string, build int) ([]*common.Status, error) {
|
|||
})
|
||||
return statuses, err
|
||||
}
|
||||
|
||||
*/
|
||||
// SetStatus inserts a new build status for the
|
||||
// named repository and build number. If the status already
|
||||
// exists an error is returned.
|
||||
|
@ -160,7 +161,6 @@ func (db *DB) SetStatus(repo string, build int, status *common.Status) error {
|
|||
}
|
||||
|
||||
// Experimental
|
||||
|
||||
func (db *DB) SetBuildState(repo string, build *common.Build) error {
|
||||
key := []byte(repo + "/" + strconv.Itoa(build.Number))
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package bolt
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/drone/drone/common"
|
||||
. "github.com/franela/goblin"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuild(t *testing.T) {
|
||||
|
@ -13,6 +12,11 @@ func TestBuild(t *testing.T) {
|
|||
g.Describe("Build", func() {
|
||||
var db *DB // temporary database
|
||||
repo := string("github.com/octopod/hq")
|
||||
//testUser := &common.User{Login: "octocat"}
|
||||
//testRepo := &common.Repo{FullName: "github.com/octopod/hq"}
|
||||
testUser := "octocat"
|
||||
testRepo := "github.com/octopod/hq"
|
||||
//testBuild := 1
|
||||
|
||||
// create a new database before each unit
|
||||
// test and destroy afterwards.
|
||||
|
@ -62,5 +66,51 @@ func TestBuild(t *testing.T) {
|
|||
g.Assert(err).Equal(nil)
|
||||
g.Assert(len(builds)).Equal(3)
|
||||
})
|
||||
|
||||
g.It("Should set build status: SetBuildStatus()", func() {
|
||||
//err := db.SetRepoNotExists(testUser, testRepo)
|
||||
err := db.SetRepoNotExists(&common.User{Login: testUser}, &common.Repo{FullName: testRepo})
|
||||
g.Assert(err).Equal(nil)
|
||||
|
||||
db.SetBuild(repo, &common.Build{State: "error"})
|
||||
db.SetBuild(repo, &common.Build{State: "pending"})
|
||||
db.SetBuild(repo, &common.Build{State: "success"})
|
||||
err_ := db.SetBuildStatus(repo, 1, &common.Status{Context: "pending"})
|
||||
g.Assert(err_).Equal(nil)
|
||||
err_ = db.SetBuildStatus(repo, 2, &common.Status{Context: "running"})
|
||||
g.Assert(err_).Equal(nil)
|
||||
err_ = db.SetBuildStatus(repo, 3, &common.Status{Context: "success"})
|
||||
g.Assert(err_).Equal(nil)
|
||||
})
|
||||
|
||||
g.It("Should set build state: SetBuildState()", func() {
|
||||
err := db.SetRepoNotExists(&common.User{Login: testUser}, &common.Repo{FullName: testRepo})
|
||||
g.Assert(err).Equal(nil)
|
||||
|
||||
db.SetBuild(repo, &common.Build{State: "error"})
|
||||
db.SetBuild(repo, &common.Build{State: "pending"})
|
||||
db.SetBuild(repo, &common.Build{State: "success"})
|
||||
err_ := db.SetBuildState(repo, &common.Build{Number: 1})
|
||||
g.Assert(err_).Equal(nil)
|
||||
err_ = db.SetBuildState(repo, &common.Build{Number: 2})
|
||||
g.Assert(err_).Equal(nil)
|
||||
err_ = db.SetBuildState(repo, &common.Build{Number: 3})
|
||||
g.Assert(err_).Equal(nil)
|
||||
})
|
||||
|
||||
g.It("Should set build task: SetBuildTask()", func() {
|
||||
err := db.SetRepoNotExists(&common.User{Login: testUser}, &common.Repo{FullName: testRepo})
|
||||
g.Assert(err).Equal(nil)
|
||||
|
||||
db.SetBuild(repo, &common.Build{State: "error"})
|
||||
db.SetBuild(repo, &common.Build{State: "pending"})
|
||||
db.SetBuild(repo, &common.Build{State: "success"})
|
||||
err_ := db.SetBuildTask(repo, 1, &common.Task{Number: 1})
|
||||
g.Assert(err_).Equal(nil)
|
||||
err_ = db.SetBuildTask(repo, 1, &common.Task{Number: 2})
|
||||
g.Assert(err_).Equal(nil)
|
||||
err_ = db.SetBuildTask(repo, 2, &common.Task{Number: 1})
|
||||
g.Assert(err_).Equal(nil)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
package bolt
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/drone/drone/common"
|
||||
. "github.com/franela/goblin"
|
||||
)
|
||||
|
||||
func TestRepoDel(t *testing.T) {
|
||||
g := Goblin(t)
|
||||
g.Describe("Delete repo", func() {
|
||||
|
||||
var db *DB // temporary database
|
||||
|
||||
user := &common.User{Login: "freya"}
|
||||
repoUri := string("github.com/octopod/hq")
|
||||
|
||||
// create a new database before each unit
|
||||
// test and destroy afterwards.
|
||||
g.BeforeEach(func() {
|
||||
file, err := ioutil.TempFile(os.TempDir(), "drone-bolt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
db = Must(file.Name())
|
||||
})
|
||||
g.AfterEach(func() {
|
||||
os.Remove(db.Path())
|
||||
})
|
||||
|
||||
g.It("should cleanup", func() {
|
||||
repo := &common.Repo{FullName: repoUri}
|
||||
err := db.SetRepoNotExists(user, repo)
|
||||
g.Assert(err).Equal(nil)
|
||||
|
||||
db.SetBuild(repoUri, &common.Build{State: "success"})
|
||||
db.SetBuild(repoUri, &common.Build{State: "success"})
|
||||
db.SetBuild(repoUri, &common.Build{State: "pending"})
|
||||
|
||||
db.SetBuildStatus(repoUri, 1, &common.Status{Context: "success"})
|
||||
db.SetBuildStatus(repoUri, 2, &common.Status{Context: "success"})
|
||||
db.SetBuildStatus(repoUri, 3, &common.Status{Context: "pending"})
|
||||
|
||||
// first a little sanity to validate our test conditions
|
||||
_, err = db.BuildLast(repoUri)
|
||||
g.Assert(err).Equal(nil)
|
||||
|
||||
// now run our specific test suite
|
||||
// 1. ensure that we can delete the repo
|
||||
err = db.DelRepo(repo)
|
||||
g.Assert(err).Equal(nil)
|
||||
|
||||
// 2. ensure that deleting the repo cleans up other references
|
||||
_, err = db.Build(repoUri, 1)
|
||||
g.Assert(err).Equal(ErrKeyNotFound)
|
||||
})
|
||||
})
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ package bolt
|
|||
import (
|
||||
"github.com/drone/drone/common"
|
||||
. "github.com/franela/goblin"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
@ -128,3 +129,55 @@ func TestRepo(t *testing.T) {
|
|||
|
||||
})
|
||||
}
|
||||
|
||||
func TestRepoDel(t *testing.T) {
|
||||
g := Goblin(t)
|
||||
g.Describe("Delete repo", func() {
|
||||
|
||||
var db *DB // temporary database
|
||||
|
||||
user := &common.User{Login: "freya"}
|
||||
repoUri := string("github.com/octopod/hq")
|
||||
|
||||
// create a new database before each unit
|
||||
// test and destroy afterwards.
|
||||
g.BeforeEach(func() {
|
||||
file, err := ioutil.TempFile(os.TempDir(), "drone-bolt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
db = Must(file.Name())
|
||||
})
|
||||
g.AfterEach(func() {
|
||||
os.Remove(db.Path())
|
||||
})
|
||||
|
||||
g.It("should cleanup", func() {
|
||||
repo := &common.Repo{FullName: repoUri}
|
||||
err := db.SetRepoNotExists(user, repo)
|
||||
g.Assert(err).Equal(nil)
|
||||
|
||||
db.SetBuild(repoUri, &common.Build{State: "success"})
|
||||
db.SetBuild(repoUri, &common.Build{State: "success"})
|
||||
db.SetBuild(repoUri, &common.Build{State: "pending"})
|
||||
|
||||
db.SetBuildStatus(repoUri, 1, &common.Status{Context: "success"})
|
||||
db.SetBuildStatus(repoUri, 2, &common.Status{Context: "success"})
|
||||
db.SetBuildStatus(repoUri, 3, &common.Status{Context: "pending"})
|
||||
|
||||
// first a little sanity to validate our test conditions
|
||||
_, err = db.BuildLast(repoUri)
|
||||
g.Assert(err).Equal(nil)
|
||||
|
||||
// now run our specific test suite
|
||||
// 1. ensure that we can delete the repo
|
||||
err = db.DelRepo(repo)
|
||||
g.Assert(err).Equal(nil)
|
||||
|
||||
// 2. ensure that deleting the repo cleans up other references
|
||||
_, err = db.Build(repoUri, 1)
|
||||
g.Assert(err).Equal(ErrKeyNotFound)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -108,11 +108,11 @@ type Datastore interface {
|
|||
|
||||
// Status returns the status for the given repository
|
||||
// and build number.
|
||||
Status(string, int, string) (*common.Status, error)
|
||||
////Status(string, int, string) (*common.Status, error)
|
||||
|
||||
// StatusList returned a list of all build statues for
|
||||
// the given repository and build number.
|
||||
StatusList(string, int) ([]*common.Status, error)
|
||||
////StatusList(string, int) ([]*common.Status, error)
|
||||
|
||||
// SetStatus inserts a new build status for the
|
||||
// named repository and build number. If the status already
|
||||
|
|
Loading…
Reference in a new issue