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
Daniel Kurzynski 22ee06dc17 Enable configuration via yaml file + mavenExecute as example (#18)
* Enable configuration via yaml file
* Add documentation 
* Add tests
2017-12-06 12:03:06 +01:00

44 lines
1.4 KiB
Groovy

import org.junit.Before
import org.junit.Test
import org.yaml.snakeyaml.Yaml
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNotNull
class SetupCommonPipelineEnvironmentTest extends PiperTestBase {
def usedConfigFile
@Before
void setUp() {
super.setUp()
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)
})
helper.registerAllowedMethod("fileExists", [String], { String path ->
return path.endsWith('.pipeline/config.yml')
})
}
@Test
void testIsConfigurationAvailable() throws Exception {
def script = loadScript("test/resources/pipelines/setupCommonPipelineEnvironmentTest/loadConfiguration.groovy")
script.execute()
assertEquals('.pipeline/config.yml', usedConfigFile)
assertNotNull(script.commonPipelineEnvironment.configuration)
assertEquals('develop', script.commonPipelineEnvironment.configuration.general.productiveBranch)
assertEquals('my-maven-docker', script.commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage)
}
}