2017-12-06 12:03:06 +01:00
|
|
|
import org.junit.Before
|
2018-01-16 09:33:13 +01:00
|
|
|
import org.junit.Rule
|
2017-12-06 12:03:06 +01:00
|
|
|
import org.junit.Test
|
2018-01-26 14:55:15 +01:00
|
|
|
import org.junit.rules.RuleChain
|
2017-12-06 12:03:06 +01:00
|
|
|
import org.yaml.snakeyaml.Yaml
|
2018-06-06 11:19:19 +02:00
|
|
|
import util.BasePiperTest
|
2018-02-28 13:11:09 +01:00
|
|
|
import util.JenkinsStepRule
|
2020-03-17 09:19:09 +01:00
|
|
|
import util.JenkinsWriteFileRule
|
2019-07-31 12:22:26 +02:00
|
|
|
import util.Rules
|
2018-01-16 09:33:13 +01:00
|
|
|
|
2017-12-06 12:03:06 +01:00
|
|
|
import static org.junit.Assert.assertEquals
|
|
|
|
import static org.junit.Assert.assertNotNull
|
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
class SetupCommonPipelineEnvironmentTest extends BasePiperTest {
|
2019-03-26 14:13:03 +01:00
|
|
|
|
2018-03-02 10:57:50 +01:00
|
|
|
def usedConfigFile
|
|
|
|
|
2019-01-22 09:25:42 +01:00
|
|
|
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
2020-03-17 09:19:09 +01:00
|
|
|
private JenkinsWriteFileRule writeFileRule = new JenkinsWriteFileRule(this)
|
2018-01-16 17:06:25 +01:00
|
|
|
|
2018-01-16 09:33:13 +01:00
|
|
|
@Rule
|
2018-02-28 13:11:09 +01:00
|
|
|
public RuleChain rules = Rules
|
|
|
|
.getCommonRules(this)
|
2019-01-22 09:25:42 +01:00
|
|
|
.around(stepRule)
|
2020-03-17 09:19:09 +01:00
|
|
|
.around(writeFileRule)
|
2018-02-28 13:11:09 +01:00
|
|
|
|
2017-12-06 12:03:06 +01:00
|
|
|
@Before
|
2018-01-16 09:33:13 +01:00
|
|
|
void init() {
|
2019-03-26 14:13:03 +01:00
|
|
|
|
2017-12-06 12:03:06 +01:00
|
|
|
def examplePipelineConfig = new File('test/resources/test_pipeline_config.yml').text
|
|
|
|
|
|
|
|
helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
|
|
|
|
Yaml yamlParser = new Yaml()
|
2019-07-31 12:22:26 +02:00
|
|
|
if (parameters.text) {
|
2017-12-06 12:03:06 +01:00
|
|
|
return yamlParser.load(parameters.text)
|
|
|
|
}
|
|
|
|
usedConfigFile = parameters.file
|
|
|
|
return yamlParser.load(examplePipelineConfig)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
@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')
|
|
|
|
})
|
|
|
|
|
2019-03-26 14:13:03 +01:00
|
|
|
stepRule.step.setupCommonPipelineEnvironment(script: nullScript)
|
2017-12-06 12:03:06 +01: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 12:03:06 +01:00
|
|
|
}
|
2019-07-31 12:22:26 +02:00
|
|
|
|
|
|
|
@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)
|
|
|
|
}
|
2017-12-06 12:03:06 +01:00
|
|
|
}
|
2019-03-26 14:13:03 +01:00
|
|
|
|