diff --git a/src/main/java/org/rundeck/client/api/model/JobLoadItem.java b/src/main/java/org/rundeck/client/api/model/JobLoadItem.java index a07b8ffa..b1a0caef 100644 --- a/src/main/java/org/rundeck/client/api/model/JobLoadItem.java +++ b/src/main/java/org/rundeck/client/api/model/JobLoadItem.java @@ -40,7 +40,7 @@ public String toBasicString() { if (null != error) { return String.format( "[%s] %s%s\n\t:%s", - getId() != null ? getId() : "?", + getId() != null ? getId() : "id:?", getGroup() != null ? getGroup() + "/" : "", getName(), getError() diff --git a/src/main/java/org/rundeck/client/tool/commands/Jobs.java b/src/main/java/org/rundeck/client/tool/commands/Jobs.java index 26906cc4..80dcd1d2 100644 --- a/src/main/java/org/rundeck/client/tool/commands/Jobs.java +++ b/src/main/java/org/rundeck/client/tool/commands/Jobs.java @@ -174,7 +174,7 @@ private static void printLoadResult( CommandOutput output, final boolean isVerbose ) { - if (null != list && list.isEmpty()) { + if (null != list && !list.isEmpty()) { output.info(String.format("%d Jobs %s:%n", list.size(), title)); if (isVerbose) { output.output(list); diff --git a/src/test/groovy/org/rundeck/client/tool/commands/JobsSpec.groovy b/src/test/groovy/org/rundeck/client/tool/commands/JobsSpec.groovy index 4228bc6b..054073d0 100644 --- a/src/test/groovy/org/rundeck/client/tool/commands/JobsSpec.groovy +++ b/src/test/groovy/org/rundeck/client/tool/commands/JobsSpec.groovy @@ -21,9 +21,7 @@ import com.simplifyops.toolbelt.InputError import okhttp3.MediaType import okhttp3.ResponseBody import org.rundeck.client.api.RundeckApi -import org.rundeck.client.api.model.DeleteJobsResult -import org.rundeck.client.api.model.JobItem -import org.rundeck.client.api.model.ScheduledJobItem +import org.rundeck.client.api.model.* import org.rundeck.client.tool.RdApp import org.rundeck.client.util.Client import retrofit2.Retrofit @@ -225,4 +223,40 @@ class JobsSpec extends Specification { outFormat | result '%id %href' | '123 monkey' } + + def "job load with errors produces output"() { + given: + def api = Mock(RundeckApi) + def opts = Mock(Jobs.Load) { + isProject() >> true + getProject() >> 'ProjectName' + getFormat() >> 'yaml' + isFile() >> true + getFile() >> tempFile + } + def retrofit = new Retrofit.Builder().baseUrl('http://example.com/fake/').build() + def client = new Client(api, retrofit, 17) + def hasclient = Mock(RdApp) { + getClient() >> client + } + Jobs jobs = new Jobs(hasclient) + def out = Mock(CommandOutput) + when: + jobs.load(opts, out) + + then: + 1 * api.loadJobs('ProjectName', _, 'yaml', _, _) >> + Calls.response(new ImportResult(succeeded: [], skipped: [], failed: [ + new JobLoadItem(error: 'Test Error', name: 'Job Name') + ] + ) + ) + 0 * api._(*_) + 1 * out.info('1 Jobs Failed:\n') + 1 * out.output(['[id:?] Job Name\n\t:Test Error']) + 0 * out._(*_) + + } + + }