From 3f2d72daf0d3e2c444c417a2dffda8524332be77 Mon Sep 17 00:00:00 2001 From: Daniel Oliveira Date: Mon, 20 Apr 2015 19:57:50 -0600 Subject: [PATCH 1/6] Code changes related to PR #986 and Issue #984. Comments deleted --- datastore/bolt/task.go | 63 ------------------------------------- datastore/bolt/task_test.go | 37 ---------------------- datastore/datastore.go | 12 ------- 3 files changed, 112 deletions(-) diff --git a/datastore/bolt/task.go b/datastore/bolt/task.go index ff09fcf1..ae23a8c3 100644 --- a/datastore/bolt/task.go +++ b/datastore/bolt/task.go @@ -3,73 +3,10 @@ package bolt import ( "bytes" "github.com/boltdb/bolt" - //"github.com/drone/drone/common" "io" "strconv" ) -/* - Brad Rydzewski1:00 PM - the `Task`, `TaskList` and `SetTask` are deprecated and can be probably be removed. - I just need to make sure we aren't still using those functions anywhere else in the code -*/ -/* -// GetTask gets the task at index N for the named -// repository and build number. -func (db *DB) Task(repo string, build int, task int) (*common.Task, error) { - key := []byte(repo + "/" + strconv.Itoa(build) + "/" + strconv.Itoa(task)) - task_ := &common.Task{} - err := db.View(func(t *bolt.Tx) error { - return get(t, bucketBuildTasks, key, task_) - }) - return task_, err -} - -// TaskList gets all tasks for the named repository -// and build number. -func (db *DB) TaskList(repo string, build int) ([]*common.Task, error) { - // fetch the build so that we can get the - // number of child tasks. - build_, err := db.Build(repo, build) - if err != nil { - return nil, err - } - - t, err := db.Begin(false) - if err != nil { - return nil, err - } - defer t.Rollback() - - // based on the number of child tasks, incrment - // and loop to get each task from the bucket. - tasks := []*common.Task{} - for i := 1; i <= build_.Number; i++ { - key := []byte(repo + "/" + strconv.Itoa(build) + "/" + strconv.Itoa(i)) - raw := t.Bucket(bucketBuildTasks).Get(key) - if raw == nil { - return nil, ErrKeyNotFound - } - task := &common.Task{} - err := decode(raw, task) - if err != nil { - return nil, err - } - tasks = append(tasks, task) - } - return tasks, nil -} - -// SetTask inserts or updates a task for the named -// repository and build number. -func (db *DB) SetTask(repo string, build int, task *common.Task) error { - key := []byte(repo + "/" + strconv.Itoa(build) + "/" + strconv.Itoa(task.Number)) - return db.Update(func(t *bolt.Tx) error { - return update(t, bucketBuildTasks, key, task) - }) -} -*/ - // SetLogs inserts or updates a task logs for the // named repository and build number. func (db *DB) SetLogs(repo string, build int, task int, log []byte) error { diff --git a/datastore/bolt/task_test.go b/datastore/bolt/task_test.go index 573c7557..87d8905e 100644 --- a/datastore/bolt/task_test.go +++ b/datastore/bolt/task_test.go @@ -28,43 +28,6 @@ func TestTask(t *testing.T) { os.Remove(db.Path()) }) - /* - Brad Rydzewski1:00 PM - the `Task`, `TaskList` and `SetTask` are deprecated and can be probably be removed. - I just need to make sure we aren't still using those functions anywhere else in the code - */ - /* - g.It("Should get TaskList", func() { - db.SetRepo(&common.Repo{FullName: testRepo}) - //db.SetRepoNotExists(&common.User{Login: testUser}, &common.Repo{FullName: testRepo}) - err := db.SetTask(testRepo, testBuild, &common.Task{Number: testTask}) - g.Assert(err).Equal(nil) - err_ := db.SetTask(testRepo, testBuild, &common.Task{Number: testTask2}) - g.Assert(err_).Equal(nil) - // - tasks, err := db.TaskList(testRepo, testBuild) - // We seem to have an issue here. TaskList doesn't seem to be returning - // All the tasks added to to repo/build. So commenting these for now. - //g.Assert(err).Equal(nil) - //g.Assert(len(tasks)).Equal(2) - }) - - g.It("Should set Task", func() { - db.SetRepo(&common.Repo{FullName: testRepo}) - err := db.SetTask(testRepo, testBuild, &common.Task{Number: testTask}) - g.Assert(err).Equal(nil) - }) - - g.It("Should get Task", func() { - db.SetRepo(&common.Repo{FullName: testRepo}) - db.SetTask(testRepo, testBuild, &common.Task{Number: testTask}) - // - task, err := db.Task(testRepo, testBuild, testTask) - g.Assert(err).Equal(nil) - g.Assert(task.Number).Equal(testTask) - }) - */ - g.It("Should set Logs", func() { db.SetRepo(&common.Repo{FullName: testRepo}) //db.SetTask(testRepo, testBuild, &common.Task{Number: testTask}) diff --git a/datastore/datastore.go b/datastore/datastore.go index 19631da0..32d74498 100644 --- a/datastore/datastore.go +++ b/datastore/datastore.go @@ -119,18 +119,6 @@ type Datastore interface { // exists an error is returned. SetStatus(string, int, *common.Status) error - // GetTask gets the task at index N for the named - // repository and build number. - //Task(string, int, int) (*common.Task, error) - - // TaskList gets all tasks for the named repository - // and build number. - //TaskList(string, int) ([]*common.Task, error) - - // SetTask inserts or updates a task for the named - // repository and build number. - //SetTask(string, int, *common.Task) error - // LogReader gets the task logs at index N for // the named repository and build number. LogReader(string, int, int) (io.Reader, error) From d13c1caebf5cf8f93af81485a8e7cd3511a7d015 Mon Sep 17 00:00:00 2001 From: Daniel Oliveira Date: Wed, 22 Apr 2015 19:49:16 -0600 Subject: [PATCH 2/6] 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. --- datastore/bolt/build.go | 6 ++-- datastore/bolt/build_test.go | 56 +++++++++++++++++++++++++++-- datastore/bolt/repo_del_test.go | 63 --------------------------------- datastore/bolt/repo_test.go | 53 +++++++++++++++++++++++++++ datastore/datastore.go | 4 +-- 5 files changed, 111 insertions(+), 71 deletions(-) delete mode 100644 datastore/bolt/repo_del_test.go diff --git a/datastore/bolt/build.go b/datastore/bolt/build.go index 3d20a1be..eb3b49e0 100644 --- a/datastore/bolt/build.go +++ b/datastore/bolt/build.go @@ -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)) diff --git a/datastore/bolt/build_test.go b/datastore/bolt/build_test.go index 8f9d78b1..f26efcc6 100644 --- a/datastore/bolt/build_test.go +++ b/datastore/bolt/build_test.go @@ -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) + }) }) } diff --git a/datastore/bolt/repo_del_test.go b/datastore/bolt/repo_del_test.go deleted file mode 100644 index 22e10108..00000000 --- a/datastore/bolt/repo_del_test.go +++ /dev/null @@ -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) - }) - }) - -} diff --git a/datastore/bolt/repo_test.go b/datastore/bolt/repo_test.go index ab45babc..ed53a10f 100644 --- a/datastore/bolt/repo_test.go +++ b/datastore/bolt/repo_test.go @@ -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) + }) + }) +} diff --git a/datastore/datastore.go b/datastore/datastore.go index 32d74498..ed4f121c 100644 --- a/datastore/datastore.go +++ b/datastore/datastore.go @@ -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 From f74ca63359fc865180c25e1e1c4dcd2151afb0fb Mon Sep 17 00:00:00 2001 From: Daniel Oliveira Date: Thu, 23 Apr 2015 10:04:31 -0600 Subject: [PATCH 3/6] Disabled SetBuildTask() test until we get the nil ptr crash addressed --- datastore/bolt/build_test.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/datastore/bolt/build_test.go b/datastore/bolt/build_test.go index f26efcc6..2046ed0a 100644 --- a/datastore/bolt/build_test.go +++ b/datastore/bolt/build_test.go @@ -98,19 +98,21 @@ func TestBuild(t *testing.T) { 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) + /* + 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) - }) + 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) + }) + */ }) } From 4edf385d1c5d7581253e56d5f15eeba500022cdf Mon Sep 17 00:00:00 2001 From: Daniel Oliveira Date: Thu, 23 Apr 2015 12:15:17 -0600 Subject: [PATCH 4/6] About this commit: 1. server/builds.go:92 used SetStatus(). Replaced with SetBuildStatus(). 2. Added a index check in SetBuildTask() and return an error in case the tasks number is > than build.tasks size. --- datastore/bolt/build.go | 6 +++++- datastore/bolt/build_test.go | 28 +++++++++++++--------------- server/builds.go | 4 +++- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/datastore/bolt/build.go b/datastore/bolt/build.go index eb3b49e0..78629474 100644 --- a/datastore/bolt/build.go +++ b/datastore/bolt/build.go @@ -203,8 +203,12 @@ func (db *DB) SetBuildTask(repo string, build int, task *common.Task) error { if err != nil { return err } + if task.Number > len(build_.Tasks) { + return ErrKeyNotFound + } build_.Updated = time.Now().UTC().Unix() - build_.Tasks[task.Number] = task // TODO check index to prevent nil pointer / panic + //assuming task number is 1-based. + build_.Tasks[task.Number-1] = task // TODO check index to prevent nil pointer / panic return update(t, bucketBuild, key, build_) }) } diff --git a/datastore/bolt/build_test.go b/datastore/bolt/build_test.go index 2046ed0a..35c6a6cb 100644 --- a/datastore/bolt/build_test.go +++ b/datastore/bolt/build_test.go @@ -98,21 +98,19 @@ func TestBuild(t *testing.T) { 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) + 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) - }) - */ + 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) + }) }) } diff --git a/server/builds.go b/server/builds.go index 8535737a..0586f50a 100644 --- a/server/builds.go +++ b/server/builds.go @@ -89,7 +89,9 @@ func PostBuildStatus(c *gin.Context) { c.AbortWithStatus(400) return } - if err := store.SetStatus(repo.Name, num, in); err != nil { + + //if err := store.SetStatus(repo.Name, num, in); err != nil { + if err := store.SetBuildStatus(repo.Name, num, in); err != nil { c.Fail(400, err) } else { c.JSON(201, in) From 987e85f2614a5ca31c0c902546d142e3dcb6bcb1 Mon Sep 17 00:00:00 2001 From: Daniel Oliveira Date: Thu, 23 Apr 2015 13:39:36 -0600 Subject: [PATCH 5/6] About this commit: 1. server/builds.go:92 used SetStatus(). Replaced with SetBuildStatus(). 2. Added a index check in SetBuildTask() and return an error in case the tasks number is > than build.tasks size. --- datastore/bolt/build.go | 8 ++++---- datastore/bolt/build_test.go | 4 ---- server/builds.go | 2 -- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/datastore/bolt/build.go b/datastore/bolt/build.go index 78629474..34c06292 100644 --- a/datastore/bolt/build.go +++ b/datastore/bolt/build.go @@ -3,11 +3,10 @@ package bolt import ( //"bytes" "encoding/binary" - "strconv" - "time" - "github.com/boltdb/bolt" "github.com/drone/drone/common" + "strconv" + "time" ) // Build gets the specified build number for the @@ -203,12 +202,13 @@ func (db *DB) SetBuildTask(repo string, build int, task *common.Task) error { if err != nil { return err } + // check index to prevent nil pointer / panic if task.Number > len(build_.Tasks) { return ErrKeyNotFound } build_.Updated = time.Now().UTC().Unix() //assuming task number is 1-based. - build_.Tasks[task.Number-1] = task // TODO check index to prevent nil pointer / panic + build_.Tasks[task.Number-1] = task return update(t, bucketBuild, key, build_) }) } diff --git a/datastore/bolt/build_test.go b/datastore/bolt/build_test.go index 35c6a6cb..969a34cb 100644 --- a/datastore/bolt/build_test.go +++ b/datastore/bolt/build_test.go @@ -107,10 +107,6 @@ func TestBuild(t *testing.T) { 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) }) }) } diff --git a/server/builds.go b/server/builds.go index 0586f50a..9dd7bb6c 100644 --- a/server/builds.go +++ b/server/builds.go @@ -89,8 +89,6 @@ func PostBuildStatus(c *gin.Context) { c.AbortWithStatus(400) return } - - //if err := store.SetStatus(repo.Name, num, in); err != nil { if err := store.SetBuildStatus(repo.Name, num, in); err != nil { c.Fail(400, err) } else { From 24a0d15281f8ddebc6be8d1aa9ad3921bf760bf2 Mon Sep 17 00:00:00 2001 From: Daniel Oliveira Date: Mon, 27 Apr 2015 12:34:33 -0600 Subject: [PATCH 6/6] solved SetBuildTask() test, properly populating Tasks --- datastore/bolt/build_test.go | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/datastore/bolt/build_test.go b/datastore/bolt/build_test.go index 969a34cb..c7dcc767 100644 --- a/datastore/bolt/build_test.go +++ b/datastore/bolt/build_test.go @@ -99,13 +99,33 @@ func TestBuild(t *testing.T) { }) 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}) + err_ := db.SetRepoNotExists(&common.User{Login: testUser}, &common.Repo{FullName: testRepo}) + g.Assert(err_).Equal(nil) + // setting up tasks. + tasks := []*common.Task{ + &common.Task{ + Number: 1, + State: "pending", + ExitCode: 0, + }, + &common.Task{ + Number: 2, + State: "running", + ExitCode: 0, + }, + &common.Task{ + Number: 3, + State: "success", + ExitCode: 0, + }, + } + // setting up builds. + err_ = db.SetBuild(repo, &common.Build{Number: 1, State: "failed", Tasks: tasks}) + g.Assert(err_).Equal(nil) + err_ = db.SetBuildTask(repo, 1, &common.Task{Number: 1, State: "error", ExitCode: -1}) + g.Assert(err_).Equal(nil) + db.SetBuild(repo, &common.Build{Number: 2, State: "success", Tasks: tasks}) + err_ = db.SetBuildTask(repo, 2, &common.Task{Number: 1, State: "success", ExitCode: 0}) g.Assert(err_).Equal(nil) }) })