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/SetupCommonPipelineEnvironmentTest.groovy

70 lines
2.3 KiB
Groovy
Raw Normal View History

import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.yaml.snakeyaml.Yaml
import util.BasePiperTest
2018-02-28 14:11:09 +02:00
import util.JenkinsStepRule
import util.Rules
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNotNull
class SetupCommonPipelineEnvironmentTest extends BasePiperTest {
2019-03-26 15:13:03 +02:00
def usedConfigFile
2019-01-22 10:25:42 +02:00
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
@Rule
2018-02-28 14:11:09 +02:00
public RuleChain rules = Rules
.getCommonRules(this)
2019-01-22 10:25:42 +02:00
.around(stepRule)
2018-02-28 14:11:09 +02:00
@Before
void init() {
2019-03-26 15:13:03 +02:00
def examplePipelineConfig = new File('test/resources/test_pipeline_config.yml').text
helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
Yaml yamlParser = new Yaml()
if (parameters.text) {
return yamlParser.load(parameters.text)
}
usedConfigFile = parameters.file
return yamlParser.load(examplePipelineConfig)
})
}
@Test
void testIsYamlConfigurationAvailable() throws Exception {
helper.registerAllowedMethod("fileExists", [String], { String path ->
return path.endsWith('.pipeline/config.yml')
})
2019-03-26 15:13:03 +02:00
stepRule.step.setupCommonPipelineEnvironment(script: nullScript)
assertEquals('.pipeline/config.yml', usedConfigFile)
assertNotNull(nullScript.commonPipelineEnvironment.configuration)
assertEquals('develop', nullScript.commonPipelineEnvironment.configuration.general.productiveBranch)
assertEquals('my-maven-docker', nullScript.commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage)
}
@Test
void testWorksAlsoWithYamlFileEnding() throws Exception {
helper.registerAllowedMethod("fileExists", [String], { String path ->
return path.endsWith('.pipeline/config.yaml')
})
stepRule.step.setupCommonPipelineEnvironment(script: nullScript)
assertEquals('.pipeline/config.yaml', usedConfigFile)
assertNotNull(nullScript.commonPipelineEnvironment.configuration)
assertEquals('develop', nullScript.commonPipelineEnvironment.configuration.general.productiveBranch)
assertEquals('my-maven-docker', nullScript.commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage)
}
}
2019-03-26 15:13:03 +02:00