From 111a8e82222d99049f2f8076d455c514bbdcbcf7 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Tue, 14 Nov 2017 11:00:52 +0100 Subject: [PATCH] Handle echo calls in base class. --- test/groovy/MTABuildTest.groovy | 12 +++++------- test/groovy/NeoDeploymentTest.groovy | 10 ++++------ test/groovy/PiperTestBase.groovy | 8 ++++++++ test/groovy/ToolValidateTest.groovy | 3 --- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/test/groovy/MTABuildTest.groovy b/test/groovy/MTABuildTest.groovy index 6ea4ee37b..8b0684e41 100644 --- a/test/groovy/MTABuildTest.groovy +++ b/test/groovy/MTABuildTest.groovy @@ -17,7 +17,6 @@ public class MTABuildTest extends PiperTestBase { public TemporaryFolder tmp = new TemporaryFolder() def shellCalls = [] - def echoes = [] def currentDir def otherDir def pipeline @@ -32,7 +31,6 @@ public class MTABuildTest extends PiperTestBase { pipeline = "${tmp.newFolder("pipeline").toURI().getPath()}pipeline" helper.registerAllowedMethod('sh', [String], {s -> shellCalls.add(s)} ) - helper.registerAllowedMethod('echo', [String], {s -> echoes.add(s)} ) helper.registerAllowedMethod('readYaml', [Map], { m -> return new Yaml().load((m.file as File).text) @@ -76,7 +74,7 @@ public class MTABuildTest extends PiperTestBase { assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar" - assert echoes[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment." + assert messages[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment." } @@ -99,7 +97,7 @@ public class MTABuildTest extends PiperTestBase { assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar" - assert echoes[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment." + assert messages[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment." } @@ -124,7 +122,7 @@ public class MTABuildTest extends PiperTestBase { assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar" - assert echoes[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment." + assert messages[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment." } @Test @@ -144,7 +142,7 @@ public class MTABuildTest extends PiperTestBase { assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar" - assert echoes[1] == "[mtaBuild] Using MTA JAR from current working directory." + assert messages[1] == "[mtaBuild] Using MTA JAR from current working directory." } @@ -165,7 +163,7 @@ public class MTABuildTest extends PiperTestBase { assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar" - assert echoes[1] == "[mtaBuild] MTA JAR \"/etc/mta/mta.jar\" retrieved from parameters." + assert messages[1] == "[mtaBuild] MTA JAR \"/etc/mta/mta.jar\" retrieved from parameters." } diff --git a/test/groovy/NeoDeploymentTest.groovy b/test/groovy/NeoDeploymentTest.groovy index f702c7eea..037c6142d 100644 --- a/test/groovy/NeoDeploymentTest.groovy +++ b/test/groovy/NeoDeploymentTest.groovy @@ -23,7 +23,6 @@ class NeoDeploymentTest extends PiperTestBase { def shellCalls = [] def pipeline - def echoes = [] def archivePath @Before @@ -38,7 +37,6 @@ class NeoDeploymentTest extends PiperTestBase { shellCalls.add(s.replaceAll(/\s+/, " ").trim()) }) helper.registerAllowedMethod('error', [String], { s -> throw new AbortException(s) }) - helper.registerAllowedMethod('echo', [String], { s -> echoes.add(s) }) helper.registerAllowedMethod('usernamePassword', [Map], { m -> return m }) helper.registerAllowedMethod('withCredentials', [List, Closure], { l, c -> if(l[0].credentialsId == 'myCredentialsId') { @@ -77,7 +75,7 @@ class NeoDeploymentTest extends PiperTestBase { assert shellCalls[0] =~ /#!\/bin\/bash \/opt\/neo\/tools\/neo\.sh deploy-mta --user anonymous --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/ - assert echoes[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment." + assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment." } @@ -115,7 +113,7 @@ class NeoDeploymentTest extends PiperTestBase { assert shellCalls[0] =~ /#!\/bin\/bash \/opt\/neo\/tools\/neo\.sh deploy-mta --user defaultUser --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/ - assert echoes[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment." + assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment." } @@ -132,7 +130,7 @@ class NeoDeploymentTest extends PiperTestBase { assert shellCalls[0] =~ /#!\/bin\/bash neo deploy-mta --user defaultUser --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/ - assert echoes[1] == "Using Neo executable from PATH." + assert messages[1] == "Using Neo executable from PATH." } @@ -149,7 +147,7 @@ class NeoDeploymentTest extends PiperTestBase { assert shellCalls[0] =~ /#!\/bin\/bash \/etc\/neo\/tools\/neo\.sh deploy-mta --user anonymous --host test\.deploy\.host\.com --source ".*" --account trialuser123 --password \*\*\*\*\*\*\*\* --synchronous/ - assert echoes[1] == "[neoDeploy] Neo executable \"/etc/neo/tools/neo.sh\" retrieved from parameters." + assert messages[1] == "[neoDeploy] Neo executable \"/etc/neo/tools/neo.sh\" retrieved from parameters." } diff --git a/test/groovy/PiperTestBase.groovy b/test/groovy/PiperTestBase.groovy index f89e8f129..a9adf769f 100644 --- a/test/groovy/PiperTestBase.groovy +++ b/test/groovy/PiperTestBase.groovy @@ -5,9 +5,17 @@ import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library public class PiperTestBase extends BasePipelineTest { + protected messages = [] + protected final void _setUp() { + super.setUp() + + messages.clear() + preparePiperLib() + + helper.registerAllowedMethod('echo', [String], {s -> messages.add(s)} ) } private preparePiperLib() { diff --git a/test/groovy/ToolValidateTest.groovy b/test/groovy/ToolValidateTest.groovy index ff70a0023..7b6e59b8c 100644 --- a/test/groovy/ToolValidateTest.groovy +++ b/test/groovy/ToolValidateTest.groovy @@ -16,7 +16,6 @@ class ToolValidateTest extends PiperTestBase { public TemporaryFolder tmp = new TemporaryFolder() private notEmptyDir - private messages = [] private script @@ -25,8 +24,6 @@ class ToolValidateTest extends PiperTestBase { super._setUp() - helper.registerAllowedMethod('echo', [String], {s -> messages.add(s)}) - def pipelinePath = "${tmp.newFolder("pipeline").toURI().getPath()}pipeline" createPipeline(pipelinePath) script = loadScript(pipelinePath)