mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-06-02 23:17:33 +02:00
70 lines
2.3 KiB
Groovy
70 lines
2.3 KiB
Groovy
|
#!groovy
|
||
|
package stages
|
||
|
|
||
|
import org.junit.Before
|
||
|
import org.junit.Rule
|
||
|
import org.junit.Test
|
||
|
import org.junit.rules.ExpectedException
|
||
|
import org.junit.rules.RuleChain
|
||
|
import util.BasePiperTest
|
||
|
import util.JenkinsReadYamlRule
|
||
|
import util.JenkinsStepRule
|
||
|
import util.Rules
|
||
|
|
||
|
import static org.hamcrest.Matchers.*
|
||
|
import static org.junit.Assert.assertThat
|
||
|
|
||
|
class PiperPipelineStagePostTest extends BasePiperTest {
|
||
|
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||
|
private ExpectedException thrown = ExpectedException.none()
|
||
|
|
||
|
@Rule
|
||
|
public RuleChain rules = Rules
|
||
|
.getCommonRules(this)
|
||
|
.around(new JenkinsReadYamlRule(this))
|
||
|
.around(thrown)
|
||
|
.around(jsr)
|
||
|
|
||
|
private List stepsCalled = []
|
||
|
|
||
|
@Before
|
||
|
void init() {
|
||
|
binding.variables.env.STAGE_NAME = 'Release'
|
||
|
|
||
|
helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body ->
|
||
|
assertThat(m.stageName, is('Release'))
|
||
|
return body()
|
||
|
})
|
||
|
helper.registerAllowedMethod('influxWriteData', [Map.class], {m -> stepsCalled.add('influxWriteData')})
|
||
|
helper.registerAllowedMethod('slackSendNotification', [Map.class], {m -> stepsCalled.add('slackSendNotification')})
|
||
|
helper.registerAllowedMethod('mailSendNotification', [Map.class], {m -> stepsCalled.add('mailSendNotification')})
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
void testPostDefault() {
|
||
|
jsr.step.piperPipelineStagePost(script: nullScript, juStabUtils: utils)
|
||
|
|
||
|
assertThat(stepsCalled, hasItems('influxWriteData','mailSendNotification'))
|
||
|
assertThat(stepsCalled, not(hasItems('slackSendNotification')))
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
void testPostNotOnProductiveBranch() {
|
||
|
binding.variables.env.BRANCH_NAME = 'anyOtherBranch'
|
||
|
|
||
|
jsr.step.piperPipelineStagePost(script: nullScript, juStabUtils: utils)
|
||
|
|
||
|
assertThat(stepsCalled, hasItems('influxWriteData','mailSendNotification'))
|
||
|
assertThat(stepsCalled, not(hasItems('slackSendNotification')))
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
void testPostWithSlackNotification() {
|
||
|
nullScript.commonPipelineEnvironment.configuration = [runStep: ['Post Actions': [slackSendNotification: true]]]
|
||
|
|
||
|
jsr.step.piperPipelineStagePost(script: nullScript, juStabUtils: utils)
|
||
|
|
||
|
assertThat(stepsCalled, hasItems('influxWriteData','mailSendNotification','slackSendNotification'))
|
||
|
}
|
||
|
}
|