Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #168 add --require to executions deletebulk #170

Merged
merged 1 commit into from
Apr 27, 2018
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
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