github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/model/notify_history_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/testutil" 8 . "github.com/smartystreets/goconvey/convey" 9 "gopkg.in/mgo.v2/bson" 10 ) 11 12 var notifyHistoryTestConfig = testutil.TestConfig() 13 14 func init() { 15 db.SetGlobalSessionProvider( 16 db.SessionFactoryFromConfig(notifyHistoryTestConfig)) 17 } 18 19 func TestGenericNotificationFinding(t *testing.T) { 20 21 Convey("When finding notifications", t, func() { 22 23 testutil.HandleTestingErr(db.Clear(NotifyHistoryCollection), 24 t, "Error clearing '%v' collection", NotifyHistoryCollection) 25 26 Convey("when finding one notification", func() { 27 28 Convey("the matching notification should be returned", func() { 29 30 nHistoryOne := &NotificationHistory{ 31 Id: bson.NewObjectId(), 32 } 33 So(nHistoryOne.Insert(), ShouldBeNil) 34 35 nHistoryTwo := &NotificationHistory{ 36 Id: bson.NewObjectId(), 37 } 38 So(nHistoryTwo.Insert(), ShouldBeNil) 39 40 found, err := FindOneNotification( 41 bson.M{ 42 NHIdKey: nHistoryOne.Id, 43 }, 44 db.NoProjection, 45 ) 46 So(err, ShouldBeNil) 47 So(found.Id, ShouldEqual, nHistoryOne.Id) 48 49 found, err = FindOneNotification( 50 bson.M{ 51 NHIdKey: nHistoryTwo.Id, 52 }, 53 db.NoProjection, 54 ) 55 So(err, ShouldBeNil) 56 So(found.Id, ShouldEqual, nHistoryTwo.Id) 57 }) 58 59 }) 60 61 }) 62 63 } 64 65 func TestUpdatingNotifications(t *testing.T) { 66 67 Convey("When updating notifications", t, func() { 68 69 testutil.HandleTestingErr(db.Clear(NotifyHistoryCollection), 70 t, "Error clearing '%v' collection", NotifyHistoryCollection) 71 72 Convey("updating one notification should update the specified"+ 73 " notification in the database", func() { 74 75 nHistory := &NotificationHistory{ 76 Id: bson.NewObjectId(), 77 } 78 So(nHistory.Insert(), ShouldBeNil) 79 80 So(UpdateOneNotification( 81 bson.M{ 82 NHIdKey: nHistory.Id, 83 }, 84 bson.M{ 85 "$set": bson.M{ 86 NHPrevIdKey: "prevId", 87 }, 88 }, 89 ), ShouldBeNil) 90 91 found, err := FindOneNotification( 92 bson.M{ 93 NHIdKey: nHistory.Id, 94 }, 95 db.NoProjection, 96 ) 97 So(err, ShouldBeNil) 98 So(found.PrevNotificationId, ShouldEqual, "prevId") 99 100 }) 101 102 }) 103 104 }