github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/alerts/email_test.go (about) 1 package alerts 2 3 import ( 4 "testing" 5 6 "github.com/evergreen-ci/evergreen" 7 "github.com/evergreen-ci/evergreen/apimodels" 8 "github.com/evergreen-ci/evergreen/model" 9 "github.com/evergreen-ci/evergreen/model/alert" 10 "github.com/evergreen-ci/evergreen/model/alertrecord" 11 "github.com/evergreen-ci/evergreen/model/build" 12 "github.com/evergreen-ci/evergreen/model/task" 13 "github.com/evergreen-ci/evergreen/model/version" 14 . "github.com/smartystreets/goconvey/convey" 15 ) 16 17 const ( 18 ProjectName = "Test Project" 19 ProjectOwner = "testprojowner" 20 ProjectId = "testproject" 21 VersionRevision = "aaaaaaaaaaaaaaaaaaa" 22 VersionMessage = "bbbbbbbbbb" 23 BuildName = "Linux 64" 24 BuildId = "b1" 25 TaskName = "mainTests" 26 TaskId = "t1" 27 TestName1 = "local/jstests/big_test.js" 28 TestName2 = "FunUnitTest" 29 TestName3 = `Windows\test\cool.exe` 30 ) 31 32 func TestEmailSubject(t *testing.T) { 33 Convey("With failed task alert types:", t, func() { 34 ctx := AlertContext{ 35 AlertRequest: &alert.AlertRequest{ 36 Trigger: alertrecord.TaskFailedId, 37 }, 38 ProjectRef: &model.ProjectRef{DisplayName: ProjectName}, 39 Task: &task.Task{ 40 DisplayName: TaskName, 41 Details: apimodels.TaskEndDetail{}, 42 }, 43 Build: &build.Build{DisplayName: BuildName}, 44 Version: &version.Version{Revision: VersionRevision}, 45 } 46 Convey("a task that timed out should return a subject", func() { 47 ctx.Task.Details.TimedOut = true 48 subj := getSubject(ctx) 49 So(subj, ShouldNotEqual, "") 50 Convey("denoting the time out and showing the task name", func() { 51 So(subj, ShouldContainSubstring, "Timed Out") 52 So(subj, ShouldContainSubstring, TaskName) 53 So(subj, ShouldContainSubstring, BuildName) 54 So(subj, ShouldContainSubstring, VersionRevision[0:8]) 55 So(subj, ShouldNotContainSubstring, VersionRevision[0:9]) 56 So(subj, ShouldContainSubstring, ProjectName) 57 }) 58 }) 59 Convey("a task that failed on a system command should return a subject", func() { 60 ctx.Task.Details.Type = model.SystemCommandType 61 subj := getSubject(ctx) 62 So(subj, ShouldNotEqual, "") 63 Convey("denoting the system failure and showing the task name", func() { 64 So(subj, ShouldContainSubstring, "System") 65 So(subj, ShouldContainSubstring, TaskName) 66 So(subj, ShouldContainSubstring, BuildName) 67 So(subj, ShouldContainSubstring, VersionRevision[0:8]) 68 So(subj, ShouldContainSubstring, ProjectName) 69 }) 70 }) 71 Convey("a task that failed on a normal command with no tests should return a subject", func() { 72 subj := getSubject(ctx) 73 So(subj, ShouldNotEqual, "") 74 Convey("denoting the failure and showing the task name", func() { 75 So(subj, ShouldContainSubstring, "Task Failed") 76 So(subj, ShouldContainSubstring, TaskName) 77 So(subj, ShouldContainSubstring, BuildName) 78 So(subj, ShouldContainSubstring, VersionRevision[0:8]) 79 So(subj, ShouldContainSubstring, ProjectName) 80 }) 81 }) 82 Convey("a task with two failed tests should return a subject", func() { 83 ctx.Task.TestResults = []task.TestResult{ 84 {TestFile: TestName1, Status: evergreen.TestFailedStatus}, 85 {TestFile: TestName2, Status: evergreen.TestFailedStatus}, 86 {TestFile: TestName3, Status: evergreen.TestSucceededStatus}, 87 {TestFile: TestName3, Status: evergreen.TestSucceededStatus}, 88 {TestFile: TestName3, Status: evergreen.TestSucceededStatus}, 89 {TestFile: TestName3, Status: evergreen.TestSucceededStatus}, 90 } 91 subj := getSubject(ctx) 92 So(subj, ShouldNotEqual, "") 93 Convey("denoting the failure and showing the task name and failed tests", func() { 94 So(subj, ShouldContainSubstring, "Test Failures") 95 So(subj, ShouldContainSubstring, TaskName) 96 So(subj, ShouldContainSubstring, BuildName) 97 So(subj, ShouldContainSubstring, VersionRevision[0:8]) 98 So(subj, ShouldContainSubstring, ProjectName) 99 So(subj, ShouldContainSubstring, "big_test.js") 100 So(subj, ShouldContainSubstring, "FunUnitTest") 101 So(subj, ShouldNotContainSubstring, "cool.exe") 102 Convey("with test names properly truncated", func() { 103 So(subj, ShouldNotContainSubstring, "local") 104 So(subj, ShouldNotContainSubstring, "jstest") 105 }) 106 }) 107 }) 108 Convey("a task with five failed tests should return a subject", func() { 109 ctx.Task.TestResults = []task.TestResult{ 110 {TestFile: TestName1, Status: evergreen.TestFailedStatus}, 111 {TestFile: TestName2, Status: evergreen.TestFailedStatus}, 112 {TestFile: TestName3, Status: evergreen.TestFailedStatus}, 113 {TestFile: TestName3, Status: evergreen.TestFailedStatus}, 114 {TestFile: TestName3, Status: evergreen.TestFailedStatus}, 115 } 116 subj := getSubject(ctx) 117 So(subj, ShouldNotEqual, "") 118 Convey("denoting two test failures but hiding the rest", func() { 119 So(subj, ShouldContainSubstring, "Test Failures") 120 So(subj, ShouldContainSubstring, TaskName) 121 So(subj, ShouldContainSubstring, BuildName) 122 So(subj, ShouldContainSubstring, VersionRevision[0:8]) 123 So(subj, ShouldContainSubstring, ProjectName) 124 So(subj, ShouldContainSubstring, "big_test.js") 125 So(subj, ShouldContainSubstring, "FunUnitTest") 126 So(subj, ShouldNotContainSubstring, "cool.exe") 127 So(subj, ShouldContainSubstring, "+3 more") 128 }) 129 }) 130 Convey("a failed task with passing tests should return a subject", func() { 131 ctx.Task.TestResults = []task.TestResult{ 132 {TestFile: TestName1, Status: evergreen.TestSucceededStatus}, 133 {TestFile: TestName2, Status: evergreen.TestSucceededStatus}, 134 {TestFile: TestName3, Status: evergreen.TestSucceededStatus}, 135 } 136 subj := getSubject(ctx) 137 So(subj, ShouldNotEqual, "") 138 Convey("denoting a task failure without a parenthetical", func() { 139 So(subj, ShouldContainSubstring, "Task Failed") 140 So(subj, ShouldContainSubstring, TaskName) 141 So(subj, ShouldContainSubstring, BuildName) 142 So(subj, ShouldContainSubstring, VersionRevision[0:8]) 143 So(subj, ShouldContainSubstring, ProjectName) 144 So(subj, ShouldNotContainSubstring, "big_test.js") 145 So(subj, ShouldNotContainSubstring, "FunUnitTest") 146 So(subj, ShouldNotContainSubstring, "cool.exe") 147 So(subj, ShouldNotContainSubstring, "(") 148 So(subj, ShouldNotContainSubstring, ")") 149 }) 150 }) 151 152 }) 153 154 }