github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/model/push_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/task" 8 "github.com/evergreen-ci/evergreen/model/version" 9 "github.com/evergreen-ci/evergreen/testutil" 10 . "github.com/smartystreets/goconvey/convey" 11 ) 12 13 var pushTestConfig = testutil.TestConfig() 14 15 func init() { 16 db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(pushTestConfig)) 17 } 18 19 func TestFindPushLogAfter(t *testing.T) { 20 21 Convey("When checking for duplicate pushes", t, func() { 22 23 testutil.HandleTestingErr(db.Clear(PushlogCollection), t, "Error clearing"+ 24 " '%v' collection", PushlogCollection) 25 26 fileLoc := "s3://test/location" 27 28 Convey("if there is no conflicting push, then nothing should be"+ 29 " returned", func() { 30 31 versionOne := &version.Version{ 32 Id: "versionIdOne", 33 RevisionOrderNumber: 500, 34 } 35 36 pushLog, err := FindPushLogAfter(fileLoc, versionOne.RevisionOrderNumber) 37 So(err, ShouldBeNil) 38 So(pushLog, ShouldBeNil) 39 40 }) 41 42 Convey("if there is a push at the same location for an older commit,"+ 43 " nothing should be returned", func() { 44 45 versionOne := &version.Version{ 46 Id: "versionIdOne", 47 RevisionOrderNumber: 500, 48 } 49 50 t := &task.Task{ 51 Id: "taskId", 52 } 53 54 pushLog := NewPushLog(versionOne, t, fileLoc) 55 So(pushLog.Insert(), ShouldBeNil) 56 57 versionTwo := &version.Version{ 58 Id: "versionIdTwo", 59 RevisionOrderNumber: 600, 60 } 61 62 pushLog, err := FindPushLogAfter(fileLoc, versionTwo.RevisionOrderNumber) 63 So(err, ShouldBeNil) 64 So(pushLog, ShouldBeNil) 65 66 }) 67 68 Convey("if there is a push at the same location for the same commit,"+ 69 " it should be returned", func() { 70 71 versionOne := &version.Version{ 72 Id: "versionIdOne", 73 RevisionOrderNumber: 500, 74 } 75 76 t := &task.Task{ 77 Id: "taskId", 78 } 79 80 pushLog := NewPushLog(versionOne, t, fileLoc) 81 So(pushLog.Insert(), ShouldBeNil) 82 83 pushLog, err := FindPushLogAfter(fileLoc, versionOne.RevisionOrderNumber) 84 So(err, ShouldBeNil) 85 So(pushLog, ShouldNotBeNil) 86 87 }) 88 89 Convey("if there is a push at the same location for a newer commit,"+ 90 " it should be returned", func() { 91 92 versionOne := &version.Version{ 93 Id: "versionIdOne", 94 RevisionOrderNumber: 500, 95 } 96 97 t := &task.Task{ 98 Id: "taskId", 99 } 100 101 pushLog := NewPushLog(versionOne, t, fileLoc) 102 So(pushLog.Insert(), ShouldBeNil) 103 104 versionTwo := &version.Version{ 105 Id: "versionIdTwo", 106 RevisionOrderNumber: 400, 107 } 108 109 pushLog, err := FindPushLogAfter(fileLoc, versionTwo.RevisionOrderNumber) 110 So(err, ShouldBeNil) 111 So(pushLog, ShouldNotBeNil) 112 113 }) 114 115 }) 116 117 }