Skip to content

Commit

Permalink
Fix #168 add --require to executions deletebulk
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Apr 27, 2018
1 parent 7588960 commit c0eca5b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/org/rundeck/client/tool/commands/Executions.java
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,11 @@ public static void outputExecutionList(
String getIdlist();

boolean isIdlist();

@Option(shortName = "R",
longName = "require",
description = "Treat 0 query results as failure, otherwise succeed if no executions were returned")
boolean require();
}

@Command(description = "Find and delete executions in a project. Use the query options to find and delete " +
Expand All @@ -587,10 +592,14 @@ public boolean deletebulk(BulkDeleteCmd options, CommandOutput out) throws IOExc
.stream()
.map(Execution::getId)
.collect(Collectors.toList());
}
if (null == execIds || execIds.size() < 1) {
out.warning("No executions found to delete");
return false;
if (null == execIds || execIds.size() < 1) {
if (!options.require()) {
out.info("No executions found to delete");
} else {
out.warning("No executions found to delete");
}
return !options.require();
}
}

if (!options.isConfirm()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,37 @@ import spock.lang.Specification
* @since 12/5/16
*/
class ExecutionsSpec extends Specification {
def "deletebulk with 0 query results result with require option"() {

given:
def api = Mock(RundeckApi)

def retrofit = new Retrofit.Builder().baseUrl('http://example.com/fake/').build()
def client = new Client(api, retrofit, null, null, 18, true, null)
def hasclient = Mock(RdApp) {
getClient() >> client
getAppConfig() >> Mock(AppConfig)
}
Executions command = new Executions(hasclient)
def out = Mock(CommandOutput)
def options = Mock(Executions.BulkDeleteCmd) {
getProject() >> 'aproject'
require() >> reqd
}

when:
def result = command.deletebulk(options, out)
then:
1 * api.listExecutions('aproject', [max: '20', offset: '0'], null, null, null, null) >> Calls.response(
new ExecutionList(paging: new Paging(offset: 0, max: 20, total: 0, count: 0), executions: [])
)
result == expect

where:
reqd | expect
true | false
false | true
}
def "output format allows job.* params"() {
given:
def api = Mock(RundeckApi)
Expand Down

0 comments on commit c0eca5b

Please sign in to comment.