1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Simplify code: failExecution can be replaced by closure raising exception (#795)

This commit is contained in:
Marcus Holl 2019-08-06 13:12:59 +02:00 committed by GitHub
parent e954e3b629
commit 0c90da6638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 16 deletions

View File

@ -519,8 +519,8 @@ class NeoDeployTest extends BasePiperTest {
@Test
void showLogsOnFailingDeployment() {
thrown.expect(Exception)
shellRule.failExecution(Type.REGEX, '.* deploy .*')
thrown.expect(AbortException)
shellRule.setReturnValue(Type.REGEX, '.* deploy .*', {throw new AbortException()})
stepRule.step.neoDeploy(script: nullScript,
source: warArchiveName,

View File

@ -42,7 +42,6 @@ class JenkinsShellCallRule implements TestRule {
List shell = []
Map<Command, String> returnValues = [:]
List<Command> failingCommands = []
JenkinsShellCallRule(BasePipelineTest testInstance) {
this.testInstance = testInstance
@ -56,25 +55,12 @@ class JenkinsShellCallRule implements TestRule {
returnValues[new Command(type, script)] = value
}
def failExecution(type, script) {
failingCommands.add(new Command(type, script))
}
def handleShellCall(Map parameters) {
def unifiedScript = unify(parameters.script)
shell.add(unifiedScript)
for (Command failingCommand: failingCommands){
if(failingCommand.type == Type.REGEX && unifiedScript =~ failingCommand.script) {
throw new Exception("Script execution failed!")
} else if(failingCommand.type == Type.PLAIN && unifiedScript.equals(failingCommand.script)) {
throw new Exception("Script execution failed!")
}
}
def result = null
for(def e : returnValues.entrySet()) {