Skip to content

Commit

Permalink
fix up tests for 2023.05 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedor Rumyantsev committed May 18, 2023
1 parent 1fef160 commit 4641fee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,18 +542,6 @@ open class BaseSlackTestCase : BaseNotificationRulesTestCase() {
assertTrue(mySlackApi.messages.last().text!!.length < 1000)
}

fun `then exception is logged in the build log`(exceptionMessage: String) {
val prefix = "Service message notification exception: "
val errorMessages = runningBuild.buildLog.errorMessages
val exceptions = errorMessages
.filter {it.text.contains(prefix)}
.map { it.text }
assertEquals(
listOf(prefix + exceptionMessage),
exceptions
)
}

private fun waitForMessage() {
waitForAssert(BooleanSupplier {
mySlackApi.messages.isNotEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class SlackNotifierTest : BaseSlackTestCase() {
@Test
fun `service message notification should fail if no connections allow it`() {
`when service message notification is sent`()
`then exception is logged in the build log`("Could not find any suitable Slack connection with service message notifications enabled")
0.`messages should be sent`()
}

@Test
Expand All @@ -271,21 +271,28 @@ class SlackNotifierTest : BaseSlackTestCase() {
fun `service message notification should fail if more than one connection allow it`() {
`given there are more multiple connections allowing service message notifications`()
`when service message notification is sent`()
`then exception is logged in the build log`("More than one suitable Slack connection was found, please specify 'connectionId' argument to explicitly select connection")
0.`messages should be sent`()
}

@Test
fun `service message notification should fail if notification limit is reached`() {
`given there is connection allowing service message notifications`(1)
`when multiple service message notifications are sent`(count = 2)
`then exception is logged in the build log`("Reached limit of 1 service message Slack notifications per build")
1.`messages should be sent`()
}

@Test
fun `service message notification should honor -1 notification limit`() {
`given there is connection allowing service message notifications`(-1)
`when service message notification is sent`()
`then message should contain`("service message")
}

@Test
fun `service message notification should fail if there are external domains not in whitelist`() {
`given there is connection allowing service message notifications`(1)
`when service message notification is sent`(message = "link to externaldomain.com")
`then exception is logged in the build log`("Found external domains that are not allowed by configuration: [externaldomain.com]")
0.`messages should be sent`()
}

@Test
Expand Down

0 comments on commit 4641fee

Please sign in to comment.