/
ProjectsSpec.groovy
58 lines (49 loc) · 1.72 KB
/
ProjectsSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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/']
}
}