Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static class FileOptions {
}

@CommandLine.Command(description = "Setup SCM Config for a Project")
public boolean setup(
public int setup(
@CommandLine.Mixin BaseOpts opts,
@CommandLine.Mixin TypeOptions typeOptions,
@CommandLine.Mixin FileOptions fileOptions
Expand Down Expand Up @@ -151,14 +151,14 @@ public boolean setup(
"Setup config Validation for file: " + fileOptions.getFile().getAbsolutePath(),
getRdTool().getAppConfig().isAnsiEnabled()
)) {
return false;
return 2;
}

//otherwise check other error codes and fail if necessary
ScmActionResult result = getRdTool().getClient().checkError(response);


return outputScmActionResult(getRdOutput(), result, "Setup");
return outputScmActionResult(getRdOutput(), result, "Setup") ? 0 : 1;
}

private boolean outputScmActionResult(final CommandOutput output, final ScmActionResult result, final String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,42 @@ class SCMSpec extends Specification {

result==1
}

@Unroll
def "setup exit code #expected for #desc"() {
given:
def api = Mock(RundeckApi)
def rdTool = setupMock(api)
def out = rdTool.getRdApp().getOutput()
def scm = new SCM()
scm.rdTool = rdTool
scm.rdOutput = out

def baseopts = new SCM.BaseOpts()
baseopts.project = 'aproject'
baseopts.integration = 'import'
def typeOpts = new SCM.TypeOptions(type: 'git-import')
def tempFile = File.createTempFile('scm-setup', '.json')
tempFile.deleteOnExit()
tempFile.text = '{"config":{}}'
def fileOpts = new SCM.FileOptions(file: tempFile)

when:
def result = scm.setup(baseopts, typeOpts, fileOpts)

then:
1 * api.setupScmConfig('aproject', 'import', 'git-import', _) >> response
result == expected

where:
desc | expected | response
'success' | 0 | Calls.response(new ScmActionResult(success: true))
'failure' | 1 | Calls.response(new ScmActionResult(success: false))
'validation error' | 2 | Calls.response(
Response.error(400, ResponseBody.create(
'{"message":"Error parsing JSON","success":false}',
Client.MEDIA_TYPE_JSON
))
)
}
}
Loading