2017-12-06 13:03:06 +02:00
|
|
|
import org.junit.Before
|
2018-01-16 10:33:13 +02:00
|
|
|
import org.junit.Rule
|
2017-12-06 13:03:06 +02:00
|
|
|
import org.junit.Test
|
2018-01-26 15:55:15 +02:00
|
|
|
import org.junit.rules.RuleChain
|
2017-12-06 13:03:06 +02:00
|
|
|
import org.yaml.snakeyaml.Yaml
|
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
import util.BasePiperTest
|
2018-01-26 15:55:15 +02:00
|
|
|
import util.Rules
|
2018-08-31 10:22:43 +02:00
|
|
|
import util.JenkinsReadYamlRule
|
2018-02-28 14:11:09 +02:00
|
|
|
import util.JenkinsStepRule
|
2018-01-16 10:33:13 +02:00
|
|
|
|
2017-12-06 13:03:06 +02:00
|
|
|
import static org.junit.Assert.assertEquals
|
|
|
|
import static org.junit.Assert.assertNotNull
|
|
|
|
|
2018-08-31 10:22:43 +02:00
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
class SetupCommonPipelineEnvironmentTest extends BasePiperTest {
|
2018-03-02 11:57:50 +02:00
|
|
|
def usedConfigFile
|
|
|
|
|
2018-02-28 14:11:09 +02:00
|
|
|
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
2018-01-16 18:06:25 +02:00
|
|
|
|
2018-01-16 10:33:13 +02:00
|
|
|
@Rule
|
2018-02-28 14:11:09 +02:00
|
|
|
public RuleChain rules = Rules
|
|
|
|
.getCommonRules(this)
|
|
|
|
.around(jsr)
|
|
|
|
|
2017-12-06 13:03:06 +02:00
|
|
|
@Before
|
2018-01-16 10:33:13 +02:00
|
|
|
void init() {
|
2017-12-06 13:03:06 +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)
|
|
|
|
})
|
2018-09-27 15:45:28 +02:00
|
|
|
helper.registerAllowedMethod("readProperties", [Map], { Map parameters ->
|
|
|
|
usedConfigFile = parameters.file
|
|
|
|
Properties props = new Properties()
|
|
|
|
props.setProperty('key', 'value')
|
|
|
|
return props
|
2017-12-06 13:03:06 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2018-09-27 15:45:28 +02:00
|
|
|
void testIsYamlConfigurationAvailable() throws Exception {
|
|
|
|
|
|
|
|
helper.registerAllowedMethod("fileExists", [String], { String path ->
|
|
|
|
return path.endsWith('.pipeline/config.yml')
|
|
|
|
})
|
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
jsr.step.call(script: nullScript)
|
2017-12-06 13:03:06 +02:00
|
|
|
|
|
|
|
assertEquals('.pipeline/config.yml', usedConfigFile)
|
2018-06-06 11:19:19 +02:00
|
|
|
assertNotNull(nullScript.commonPipelineEnvironment.configuration)
|
|
|
|
assertEquals('develop', nullScript.commonPipelineEnvironment.configuration.general.productiveBranch)
|
|
|
|
assertEquals('my-maven-docker', nullScript.commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage)
|
2017-12-06 13:03:06 +02:00
|
|
|
}
|
2018-09-27 15:45:28 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void testIsPropertiesConfigurationAvailable() {
|
|
|
|
|
|
|
|
helper.registerAllowedMethod("fileExists", [String], { String path ->
|
|
|
|
return path.endsWith('.pipeline/config.properties')
|
|
|
|
})
|
|
|
|
|
|
|
|
jsr.step.call(script: nullScript)
|
|
|
|
|
|
|
|
assertEquals('.pipeline/config.properties', usedConfigFile)
|
|
|
|
assertNotNull(nullScript.commonPipelineEnvironment.configProperties)
|
|
|
|
assertEquals('value', nullScript.commonPipelineEnvironment.configProperties['key'])
|
|
|
|
}
|
|
|
|
|
2017-12-06 13:03:06 +02:00
|
|
|
}
|