1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-02-21 19:48:53 +02:00

Handle echo calls in base class.

This commit is contained in:
Marcus Holl 2017-11-14 11:00:52 +01:00
parent b5cc4565fc
commit 111a8e8222
4 changed files with 17 additions and 16 deletions

View File

@ -17,7 +17,6 @@ public class MTABuildTest extends PiperTestBase {
public TemporaryFolder tmp = new TemporaryFolder() public TemporaryFolder tmp = new TemporaryFolder()
def shellCalls = [] def shellCalls = []
def echoes = []
def currentDir def currentDir
def otherDir def otherDir
def pipeline def pipeline
@ -32,7 +31,6 @@ public class MTABuildTest extends PiperTestBase {
pipeline = "${tmp.newFolder("pipeline").toURI().getPath()}pipeline" pipeline = "${tmp.newFolder("pipeline").toURI().getPath()}pipeline"
helper.registerAllowedMethod('sh', [String], {s -> shellCalls.add(s)} ) helper.registerAllowedMethod('sh', [String], {s -> shellCalls.add(s)} )
helper.registerAllowedMethod('echo', [String], {s -> echoes.add(s)} )
helper.registerAllowedMethod('readYaml', [Map], { helper.registerAllowedMethod('readYaml', [Map], {
m -> m ->
return new Yaml().load((m.file as File).text) 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 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 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 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 @Test
@ -144,7 +142,7 @@ public class MTABuildTest extends PiperTestBase {
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar" 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 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."
} }

View File

@ -23,7 +23,6 @@ class NeoDeploymentTest extends PiperTestBase {
def shellCalls = [] def shellCalls = []
def pipeline def pipeline
def echoes = []
def archivePath def archivePath
@Before @Before
@ -38,7 +37,6 @@ class NeoDeploymentTest extends PiperTestBase {
shellCalls.add(s.replaceAll(/\s+/, " ").trim()) shellCalls.add(s.replaceAll(/\s+/, " ").trim())
}) })
helper.registerAllowedMethod('error', [String], { s -> throw new AbortException(s) }) 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('usernamePassword', [Map], { m -> return m })
helper.registerAllowedMethod('withCredentials', [List, Closure], { l, c -> helper.registerAllowedMethod('withCredentials', [List, Closure], { l, c ->
if(l[0].credentialsId == 'myCredentialsId') { 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 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 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 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 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."
} }

View File

@ -5,9 +5,17 @@ import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
public class PiperTestBase extends BasePipelineTest { public class PiperTestBase extends BasePipelineTest {
protected messages = []
protected final void _setUp() { protected final void _setUp() {
super.setUp() super.setUp()
messages.clear()
preparePiperLib() preparePiperLib()
helper.registerAllowedMethod('echo', [String], {s -> messages.add(s)} )
} }
private preparePiperLib() { private preparePiperLib() {

View File

@ -16,7 +16,6 @@ class ToolValidateTest extends PiperTestBase {
public TemporaryFolder tmp = new TemporaryFolder() public TemporaryFolder tmp = new TemporaryFolder()
private notEmptyDir private notEmptyDir
private messages = []
private script private script
@ -25,8 +24,6 @@ class ToolValidateTest extends PiperTestBase {
super._setUp() super._setUp()
helper.registerAllowedMethod('echo', [String], {s -> messages.add(s)})
def pipelinePath = "${tmp.newFolder("pipeline").toURI().getPath()}pipeline" def pipelinePath = "${tmp.newFolder("pipeline").toURI().getPath()}pipeline"
createPipeline(pipelinePath) createPipeline(pipelinePath)
script = loadScript(pipelinePath) script = loadScript(pipelinePath)