-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Job run does exact name/group query, Add jobxact/groupxact options fo…
…r job list/purge, fix #45
- Loading branch information
Showing
6 changed files
with
225 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
src/test/groovy/org/rundeck/client/tool/commands/JobsSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package org.rundeck.client.tool.commands | ||
|
||
import com.simplifyops.toolbelt.CommandOutput | ||
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.util.Client | ||
import retrofit2.Response | ||
import retrofit2.Retrofit | ||
import retrofit2.mock.Calls | ||
import spock.lang.Specification | ||
|
||
/** | ||
* @author greg | ||
* @since 12/13/16 | ||
*/ | ||
class JobsSpec extends Specification { | ||
File tempFile = File.createTempFile('data', 'out') | ||
|
||
def setup() { | ||
tempFile = File.createTempFile('data', 'out') | ||
} | ||
|
||
def cleanup() { | ||
if (tempFile.exists()) { | ||
tempFile.delete() | ||
} | ||
} | ||
|
||
def "job list with input parameters"() { | ||
given: | ||
def api = Mock(RundeckApi) | ||
|
||
def opts = Mock(Jobs.ListOpts) { | ||
isJob() >> true | ||
isProject() >> true | ||
getProject() >> 'ProjectName' | ||
getJobExact() >> jobexact | ||
getGroupExact() >> groupexact | ||
getJob() >> job | ||
getGroup() >> group | ||
} | ||
def retrofit = new Retrofit.Builder().baseUrl('http://example.com/fake/').build() | ||
def client = new Client(api, retrofit, 17) | ||
def hasclient = Mock(ApiCommand.HasClient) { | ||
getClient() >> client | ||
} | ||
Jobs jobs = new Jobs(hasclient) | ||
def out = Mock(CommandOutput) | ||
when: | ||
jobs.list(opts, out) | ||
|
||
then: | ||
1 * api.listJobs('ProjectName', job, group, jobexact, groupexact) >> | ||
Calls.response([new JobItem(id: 'fakeid')]) | ||
0 * api._(*_) | ||
|
||
where: | ||
job | group | jobexact | groupexact | ||
'a' | 'b/c' | null | null | ||
null | null | 'a' | 'b/c' | ||
} | ||
|
||
def "job list write to file with input parameters"() { | ||
given: | ||
def api = Mock(RundeckApi) | ||
def opts = Mock(Jobs.ListOpts) { | ||
isJob() >> true | ||
isProject() >> true | ||
getProject() >> 'ProjectName' | ||
getJobExact() >> jobexact | ||
getGroupExact() >> groupexact | ||
getJob() >> job | ||
getGroup() >> group | ||
isFile() >> true | ||
getFormat() >> 'xml' | ||
getFile() >> tempFile | ||
} | ||
def retrofit = new Retrofit.Builder().baseUrl('http://example.com/fake/').build() | ||
def client = new Client(api, retrofit, 17) | ||
def hasclient = Mock(ApiCommand.HasClient) { | ||
getClient() >> client | ||
} | ||
Jobs jobs = new Jobs(hasclient) | ||
def out = Mock(CommandOutput) | ||
when: | ||
jobs.list(opts, out) | ||
|
||
then: | ||
1 * api.exportJobs('ProjectName', job, group, jobexact, groupexact, 'xml') >> | ||
Calls.response(ResponseBody.create(MediaType.parse('application/xml'), 'abc')) | ||
0 * api._(*_) | ||
tempFile.exists() | ||
tempFile.text == 'abc' | ||
|
||
where: | ||
job | group | jobexact | groupexact | ||
'a' | 'b/c' | null | null | ||
null | null | 'a' | 'b/c' | ||
} | ||
|
||
|
||
def "job purge with input parameters"() { | ||
given: | ||
def api = Mock(RundeckApi) | ||
|
||
def opts = Mock(Jobs.Purge) { | ||
isJob() >> true | ||
isProject() >> true | ||
getProject() >> 'ProjectName' | ||
getJobExact() >> jobexact | ||
getGroupExact() >> groupexact | ||
getJob() >> job | ||
getGroup() >> group | ||
isConfirm() >> true | ||
} | ||
def retrofit = new Retrofit.Builder().baseUrl('http://example.com/fake/').build() | ||
def client = new Client(api, retrofit, 17) | ||
def hasclient = Mock(ApiCommand.HasClient) { | ||
getClient() >> client | ||
} | ||
Jobs jobs = new Jobs(hasclient) | ||
def out = Mock(CommandOutput) | ||
when: | ||
def result = jobs.purge(opts, out) | ||
|
||
then: | ||
1 * api.listJobs('ProjectName', job, group, jobexact, groupexact) >> | ||
Calls.response([new JobItem(id: 'fakeid')]) | ||
1 * api.deleteJobs(['fakeid']) >> Calls.response(new DeleteJobsResult(allsuccessful: true)) | ||
0 * api._(*_) | ||
result | ||
|
||
where: | ||
job | group | jobexact | groupexact | ||
'a' | 'b/c' | null | null | ||
null | null | 'a' | 'b/c' | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/groovy/org/rundeck/client/tool/commands/RunSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.rundeck.client.tool.commands | ||
|
||
import com.simplifyops.toolbelt.CommandOutput | ||
import org.rundeck.client.api.RundeckApi | ||
import org.rundeck.client.api.model.Execution | ||
import org.rundeck.client.api.model.JobItem | ||
import org.rundeck.client.tool.options.RunBaseOptions | ||
import org.rundeck.client.util.Client | ||
import retrofit2.Retrofit | ||
import retrofit2.mock.Calls | ||
import spock.lang.Specification | ||
|
||
/** | ||
* @author greg | ||
* @since 12/13/16 | ||
*/ | ||
class RunSpec extends Specification { | ||
def "run command -j queries for exact job name and group"() { | ||
|
||
given: | ||
def api = Mock(RundeckApi) | ||
|
||
def opts = Mock(RunBaseOptions) { | ||
isJob() >> true | ||
isProject() >> true | ||
getProject() >> 'ProjectName' | ||
getJob() >> 'a group/path/a job' | ||
} | ||
def retrofit = new Retrofit.Builder().baseUrl('http://example.com/fake/').build() | ||
def client = new Client(api, retrofit, 17) | ||
def hasclient = Mock(ApiCommand.HasClient) { | ||
getClient() >> client | ||
} | ||
Run run = new Run(hasclient) | ||
def out = Mock(CommandOutput) | ||
when: | ||
def result = run.run(opts, out) | ||
|
||
then: | ||
1 * api.listJobs('ProjectName', null, null, 'a job', 'a group/path') >> | ||
Calls.response([new JobItem(id: 'fakeid')]) | ||
1 * api.runJob('fakeid', null, null, null, null) >> Calls.response(new Execution(id: 123, description: '')) | ||
0 * api._(*_) | ||
result | ||
|
||
} | ||
} |