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:
parent
e954e3b629
commit
0c90da6638
@ -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,
|
||||
|
@ -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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user