From ba725dc52f19acad292ba4309be2698ddd231825 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Thu, 27 Sep 2018 15:45:28 +0200 Subject: [PATCH 1/3] test asserting setupCPE works with config properties file --- .../SetupCommonPipelineEnvironmentTest.groovy | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/test/groovy/SetupCommonPipelineEnvironmentTest.groovy b/test/groovy/SetupCommonPipelineEnvironmentTest.groovy index 8b4a022c9..d44ac3225 100644 --- a/test/groovy/SetupCommonPipelineEnvironmentTest.groovy +++ b/test/groovy/SetupCommonPipelineEnvironmentTest.groovy @@ -35,13 +35,21 @@ class SetupCommonPipelineEnvironmentTest extends BasePiperTest { usedConfigFile = parameters.file return yamlParser.load(examplePipelineConfig) }) - helper.registerAllowedMethod("fileExists", [String], { String path -> - return path.endsWith('.pipeline/config.yml') + helper.registerAllowedMethod("readProperties", [Map], { Map parameters -> + usedConfigFile = parameters.file + Properties props = new Properties() + props.setProperty('key', 'value') + return props }) } @Test - void testIsConfigurationAvailable() throws Exception { + void testIsYamlConfigurationAvailable() throws Exception { + + helper.registerAllowedMethod("fileExists", [String], { String path -> + return path.endsWith('.pipeline/config.yml') + }) + jsr.step.call(script: nullScript) assertEquals('.pipeline/config.yml', usedConfigFile) @@ -49,4 +57,19 @@ class SetupCommonPipelineEnvironmentTest extends BasePiperTest { assertEquals('develop', nullScript.commonPipelineEnvironment.configuration.general.productiveBranch) assertEquals('my-maven-docker', nullScript.commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage) } + + @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']) + } + } From 799810a987b5c0fca3aa8f78fa07c602e4193e15 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Tue, 2 Oct 2018 10:24:07 +0200 Subject: [PATCH 2/3] Accept utils instance from outside (for testing) --- vars/setupCommonPipelineEnvironment.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vars/setupCommonPipelineEnvironment.groovy b/vars/setupCommonPipelineEnvironment.groovy index 79e55be3f..5c0bdc060 100644 --- a/vars/setupCommonPipelineEnvironment.groovy +++ b/vars/setupCommonPipelineEnvironment.groovy @@ -22,7 +22,8 @@ def call(Map parameters = [:]) { .mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS) .use() - new Utils().pushToSWA([step: STEP_NAME, stepParam4: parameters.customDefaults?'true':'false'], config) + (parameter.utils ?: new Utils()) + .pushToSWA([step: STEP_NAME, stepParam4: parameters.customDefaults?'true':'false'], config) } } From afc17707d85ece7c3b6263a0b907c3d48d574e75 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Tue, 2 Oct 2018 10:53:53 +0200 Subject: [PATCH 3/3] Notify about old config (properties) used --- .../SetupCommonPipelineEnvironmentTest.groovy | 19 +++++++++++++++++-- vars/setupCommonPipelineEnvironment.groovy | 5 +++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/test/groovy/SetupCommonPipelineEnvironmentTest.groovy b/test/groovy/SetupCommonPipelineEnvironmentTest.groovy index d44ac3225..80d482fc1 100644 --- a/test/groovy/SetupCommonPipelineEnvironmentTest.groovy +++ b/test/groovy/SetupCommonPipelineEnvironmentTest.groovy @@ -4,6 +4,8 @@ import org.junit.Test import org.junit.rules.RuleChain import org.yaml.snakeyaml.Yaml +import com.sap.piper.Utils + import util.BasePiperTest import util.Rules import util.JenkinsReadYamlRule @@ -15,6 +17,7 @@ import static org.junit.Assert.assertNotNull class SetupCommonPipelineEnvironmentTest extends BasePiperTest { def usedConfigFile + def swaOldConfigUsed private JenkinsStepRule jsr = new JenkinsStepRule(this) @@ -41,6 +44,8 @@ class SetupCommonPipelineEnvironmentTest extends BasePiperTest { props.setProperty('key', 'value') return props }) + + swaOldConfigUsed = null } @Test @@ -50,8 +55,9 @@ class SetupCommonPipelineEnvironmentTest extends BasePiperTest { return path.endsWith('.pipeline/config.yml') }) - jsr.step.call(script: nullScript) + jsr.step.call(script: nullScript, utils: getSWAMockedUtils()) + assertEquals(Boolean.FALSE.toString(), swaOldConfigUsed) assertEquals('.pipeline/config.yml', usedConfigFile) assertNotNull(nullScript.commonPipelineEnvironment.configuration) assertEquals('develop', nullScript.commonPipelineEnvironment.configuration.general.productiveBranch) @@ -65,11 +71,20 @@ class SetupCommonPipelineEnvironmentTest extends BasePiperTest { return path.endsWith('.pipeline/config.properties') }) - jsr.step.call(script: nullScript) + jsr.step.call(script: nullScript, utils: getSWAMockedUtils()) + assertEquals(Boolean.TRUE.toString(), swaOldConfigUsed) assertEquals('.pipeline/config.properties', usedConfigFile) assertNotNull(nullScript.commonPipelineEnvironment.configProperties) assertEquals('value', nullScript.commonPipelineEnvironment.configProperties['key']) } + private getSWAMockedUtils() { + new Utils() { + void pushToSWA(Map payload, Map config) { + SetupCommonPipelineEnvironmentTest.this.swaOldConfigUsed = payload.stepParam5 + } + } + } + } diff --git a/vars/setupCommonPipelineEnvironment.groovy b/vars/setupCommonPipelineEnvironment.groovy index 5c0bdc060..e9a41c6b9 100644 --- a/vars/setupCommonPipelineEnvironment.groovy +++ b/vars/setupCommonPipelineEnvironment.groovy @@ -22,8 +22,9 @@ def call(Map parameters = [:]) { .mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS) .use() - (parameter.utils ?: new Utils()) - .pushToSWA([step: STEP_NAME, stepParam4: parameters.customDefaults?'true':'false'], config) + (parameters.utils ?: new Utils()) + .pushToSWA([step: STEP_NAME, stepParam4: parameters.customDefaults?'true':'false', + stepParam5: Boolean.toString( ! (script?.commonPipelineEnvironment?.getConfigProperties() ?: [:]).isEmpty())], config) } }