github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/model/dependency_test.go (about)

     1  package model
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/evergreen-ci/evergreen"
     7  	"github.com/evergreen-ci/evergreen/model/task"
     8  	"github.com/evergreen-ci/evergreen/testutil"
     9  	. "github.com/smartystreets/goconvey/convey"
    10  	"gopkg.in/mgo.v2/bson"
    11  )
    12  
    13  // We have to define a wrapper for the dependencies,
    14  // since you can't marshal BSON straight into a slice.
    15  type depTask struct {
    16  	DependsOn []task.Dependency `bson:"depends_on"`
    17  }
    18  
    19  func TestDependencyBSON(t *testing.T) {
    20  	Convey("With BSON bytes", t, func() {
    21  		Convey("representing legacy dependency format (i.e. just strings)", func() {
    22  			bytes, err := bson.Marshal(map[string]interface{}{
    23  				"depends_on": []string{"t1", "t2", "t3"},
    24  			})
    25  			testutil.HandleTestingErr(err, t, "failed to marshal test BSON")
    26  
    27  			Convey("unmarshalling the BSON into a Dependency slice should succeed", func() {
    28  				var deps depTask
    29  				So(bson.Unmarshal(bytes, &deps), ShouldBeNil)
    30  				So(len(deps.DependsOn), ShouldEqual, 3)
    31  
    32  				Convey("with the proper tasks", func() {
    33  					So(deps.DependsOn[0].TaskId, ShouldEqual, "t1")
    34  					So(deps.DependsOn[0].Status, ShouldEqual, evergreen.TaskSucceeded)
    35  					So(deps.DependsOn[1].TaskId, ShouldEqual, "t2")
    36  					So(deps.DependsOn[1].Status, ShouldEqual, evergreen.TaskSucceeded)
    37  					So(deps.DependsOn[2].TaskId, ShouldEqual, "t3")
    38  					So(deps.DependsOn[2].Status, ShouldEqual, evergreen.TaskSucceeded)
    39  				})
    40  			})
    41  		})
    42  
    43  		Convey("representing the current dependency format", func() {
    44  			inputDeps := depTask{[]task.Dependency{
    45  				{TaskId: "t1", Status: evergreen.TaskSucceeded},
    46  				{TaskId: "t2", Status: "*"},
    47  				{TaskId: "t3", Status: evergreen.TaskFailed},
    48  			}}
    49  			bytes, err := bson.Marshal(inputDeps)
    50  			testutil.HandleTestingErr(err, t, "failed to marshal test BSON")
    51  
    52  			Convey("unmarshalling the BSON into a Dependency slice should succeed", func() {
    53  				var deps depTask
    54  				So(bson.Unmarshal(bytes, &deps), ShouldBeNil)
    55  
    56  				Convey("with the proper tasks", func() {
    57  					So(deps.DependsOn, ShouldResemble, inputDeps.DependsOn)
    58  				})
    59  			})
    60  		})
    61  	})
    62  }