github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/model/host_manipulation_test.go (about) 1 package model 2 3 import ( 4 "testing" 5 6 "github.com/evergreen-ci/evergreen/db" 7 "github.com/evergreen-ci/evergreen/model/distro" 8 "github.com/evergreen-ci/evergreen/model/host" 9 "github.com/evergreen-ci/evergreen/model/task" 10 "github.com/evergreen-ci/evergreen/testutil" 11 . "github.com/smartystreets/goconvey/convey" 12 ) 13 14 func TestHostFindNextTask(t *testing.T) { 15 16 Convey("With a host", t, func() { 17 18 Convey("when finding the next task to be run on the host", func() { 19 20 testutil.HandleTestingErr(db.ClearCollections(host.Collection, 21 task.Collection, TaskQueuesCollection), t, 22 "Error clearing test collections") 23 24 h := &host.Host{Id: "hostId", Distro: distro.Distro{}} 25 So(h.Insert(), ShouldBeNil) 26 27 Convey("if there is no task queue for the host's distro, no task"+ 28 " should be returned", func() { 29 30 nextTask, err := NextTaskForHost(h) 31 So(err, ShouldBeNil) 32 So(nextTask, ShouldBeNil) 33 34 }) 35 36 Convey("if the task queue is empty, no task should be"+ 37 " returned", func() { 38 39 tQueue := &TaskQueue{Distro: h.Distro.Id} 40 So(tQueue.Save(), ShouldBeNil) 41 42 nextTask, err := NextTaskForHost(h) 43 So(err, ShouldBeNil) 44 So(nextTask, ShouldBeNil) 45 46 }) 47 48 Convey("if the task queue is not empty, the corresponding task"+ 49 " object from the database should be returned", func() { 50 51 tQueue := &TaskQueue{ 52 Distro: h.Distro.Id, 53 Queue: []TaskQueueItem{{Id: "taskOne"}}, 54 } 55 So(tQueue.Save(), ShouldBeNil) 56 57 task := &task.Task{Id: "taskOne"} 58 So(task.Insert(), ShouldBeNil) 59 60 nextTask, err := NextTaskForHost(h) 61 So(err, ShouldBeNil) 62 So(nextTask.Id, ShouldEqual, task.Id) 63 64 }) 65 66 }) 67 68 }) 69 }