-
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.
Merge pull request #69 from rundeck/rundeck-cli-68
Fix #68 improve projects list output
- Loading branch information
Showing
5 changed files
with
159 additions
and
7 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
19 changes: 19 additions & 0 deletions
19
src/main/java/org/rundeck/client/tool/options/ProjectListFormatOptions.java
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,19 @@ | ||
package org.rundeck.client.tool.options; | ||
|
||
import com.lexicalscope.jewel.cli.Option; | ||
|
||
/** | ||
* @author greg | ||
* @since 2/2/17 | ||
*/ | ||
public interface ProjectListFormatOptions { | ||
|
||
@Option(shortName = "%", | ||
longName = "outformat", | ||
description = "Output format specifier for project info. You can use \"%key\" where key is one of: " + | ||
"name, description, url, config, config.KEY. E.g. \"%name: " + | ||
"%description\".") | ||
String getOutputFormat(); | ||
|
||
boolean isOutputFormat(); | ||
} |
58 changes: 58 additions & 0 deletions
58
src/test/groovy/org/rundeck/client/tool/commands/ProjectsSpec.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,58 @@ | ||
package org.rundeck.client.tool.commands | ||
|
||
import com.simplifyops.toolbelt.CommandOutput | ||
import org.rundeck.client.api.RundeckApi | ||
import org.rundeck.client.api.model.ProjectItem | ||
import org.rundeck.client.api.model.ScheduledJobItem | ||
import org.rundeck.client.tool.RdApp | ||
import org.rundeck.client.util.Client | ||
import retrofit2.Retrofit | ||
import retrofit2.mock.Calls | ||
import spock.lang.Specification | ||
|
||
/** | ||
* @author greg | ||
* @since 2/2/17 | ||
*/ | ||
class ProjectsSpec extends Specification { | ||
|
||
def "projects list outformat"() { | ||
given: | ||
|
||
def api = Mock(RundeckApi) | ||
def opts = Mock(Projects.ProjectListOpts) { | ||
getOutputFormat() >> outFormat | ||
isOutputFormat() >> (outFormat != null) | ||
} | ||
|
||
def retrofit = new Retrofit.Builder().baseUrl('http://example.com/fake/').build() | ||
def client = new Client(api, retrofit, 18) | ||
def hasclient = Mock(RdApp) { | ||
getClient() >> client | ||
} | ||
Projects projects = new Projects(hasclient) | ||
def out = Mock(CommandOutput) | ||
|
||
when: | ||
projects.list(opts, out) | ||
|
||
then: | ||
1 * api.listProjects() >> | ||
Calls.response( | ||
[new ProjectItem(name: 'abc', description: '123', config: [xyz: '993']), new ProjectItem( | ||
name: 'def', | ||
description: '' | ||
)] | ||
) | ||
1 * out.output(result) | ||
|
||
|
||
where: | ||
outFormat | result | ||
null | ['abc', 'def'] | ||
'%name' | ['abc', 'def'] | ||
'%name/%description' | ['abc/123', 'def/'] | ||
'%name/%config' | ['abc/{xyz=993}', 'def/'] | ||
'%name/%config.xyz' | ['abc/993', 'def/'] | ||
} | ||
} |