Skip to content

Commit

Permalink
Merge pull request #114 from rundeck/rundeck-cli-113
Browse files Browse the repository at this point in the history
fix #113 show load jobs output results correctly
  • Loading branch information
gschueler authored Aug 10, 2017
2 parents e793b80 + 554bb90 commit cb53212
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/rundeck/client/tool/commands/Jobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 37 additions & 3 deletions src/test/groovy/org/rundeck/client/tool/commands/JobsSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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._(*_)

}


}

0 comments on commit cb53212

Please sign in to comment.