1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/test/groovy/PipelineStashFilesAfterBuildTest.groovy

73 lines
2.5 KiB
Groovy
Raw Normal View History

2018-05-30 12:00:13 +02:00
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import util.*
import static org.hamcrest.Matchers.containsString
import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertThat
class PipelineStashFilesAfterBuildTest extends BasePiperTest {
2019-01-22 10:25:42 +02:00
JenkinsStepRule stepRule = new JenkinsStepRule(this)
JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
JenkinsReadJsonRule readJsonRule = new JenkinsReadJsonRule(this)
2018-05-30 12:00:13 +02:00
@Rule
public RuleChain rules = Rules
.getCommonRules(this)
.around(new JenkinsReadYamlRule(this))
.around(readJsonRule)
.around(loggingRule)
2019-01-22 10:25:42 +02:00
.around(stepRule)
2018-05-30 12:00:13 +02:00
@Test
void testStashAfterBuild() {
helper.registerAllowedMethod("fileExists", [String.class], {
searchTerm ->
return false
})
2019-01-22 10:25:42 +02:00
stepRule.step.pipelineStashFilesAfterBuild(
2018-05-30 12:00:13 +02:00
script: nullScript,
juStabUtils: utils
)
// asserts
assertFalse(loggingRule.log.contains('Stash content: checkmarx'))
assertThat(loggingRule.log, containsString('Stash content: classFiles'))
assertThat(loggingRule.log, containsString('Stash content: sonar'))
2018-05-30 12:00:13 +02:00
}
@Test
void testStashAfterBuildWithCheckmarx() {
helper.registerAllowedMethod("fileExists", [String.class], {
searchTerm ->
return true
})
2019-01-22 10:25:42 +02:00
stepRule.step.pipelineStashFilesAfterBuild(
2018-05-30 12:00:13 +02:00
script: nullScript,
juStabUtils: utils,
runCheckmarx: true
)
// asserts
assertThat(loggingRule.log, containsString('Stash content: checkmarx'))
assertThat(loggingRule.log, containsString('Stash content: classFiles'))
assertThat(loggingRule.log, containsString('Stash content: sonar'))
2018-05-30 12:00:13 +02:00
}
@Test
void testStashAfterBuildWithCheckmarxConfig() {
helper.registerAllowedMethod("fileExists", [String.class], {
searchTerm ->
return true
})
2019-01-22 10:25:42 +02:00
stepRule.step.pipelineStashFilesAfterBuild(
2018-05-30 12:00:13 +02:00
script: [commonPipelineEnvironment: [configuration: [steps: [executeCheckmarxScan: [checkmarxProject: 'TestProject']]]]],
juStabUtils: utils,
)
// asserts
assertThat(loggingRule.log, containsString('Stash content: checkmarx'))
assertThat(loggingRule.log, containsString('Stash content: classFiles'))
assertThat(loggingRule.log, containsString('Stash content: sonar'))
2018-05-30 12:00:13 +02:00
}
}