-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/test/groovy/com/rundeck/plugins/ansible/ansible/AnsibleRunnerContextBuilderSpec.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,83 @@ | ||
package com.rundeck.plugins.ansible.ansible | ||
|
||
import com.dtolabs.rundeck.core.common.Framework | ||
import com.dtolabs.rundeck.core.common.INodeSet | ||
import com.dtolabs.rundeck.core.execution.ExecutionContext | ||
import com.dtolabs.rundeck.plugins.step.PluginStepContext | ||
import com.rundeck.plugins.ansible.plugin.AnsiblePluginGroup | ||
import spock.lang.Specification | ||
import com.dtolabs.rundeck.core.execution.ExecutionLogger | ||
|
||
class AnsibleRunnerContextBuilderSpec extends Specification { | ||
|
||
def "test plugin group"(){ | ||
given: | ||
|
||
PluginStepContext context = Mock(PluginStepContext){ | ||
getDataContext() >> ['job': ['loglevel':'INFO']] | ||
getExecutionContext() >> Mock(ExecutionContext){ | ||
getDataContext() >> [:] | ||
getExecutionLogger() >> Mock(ExecutionLogger) | ||
} | ||
getFramework() >> Mock(Framework) | ||
getNodes() >> Mock(INodeSet){ | ||
getNodes() >> [] | ||
} | ||
} | ||
|
||
Map<String, Object> configuration = [ | ||
'ansible-playbook' : 'path/to/playbook' | ||
] | ||
|
||
AnsiblePluginGroup pluginGroup = new AnsiblePluginGroup() | ||
pluginGroup.setAnsibleConfigFilePath("/etc/ansible/ansible.cfg") | ||
pluginGroup.setEncryptExtraVars(true) | ||
pluginGroup.setAnsibleBinariesDirPath("/usr/local/lib") | ||
|
||
when: | ||
AnsibleRunnerContextBuilder contextBuilder = new AnsibleRunnerContextBuilder(context.getExecutionContext(), | ||
context.getFramework(), | ||
context.getNodes(), | ||
configuration, | ||
pluginGroup) | ||
|
||
then: | ||
contextBuilder.getConfigFile() == "/etc/ansible/ansible.cfg" | ||
contextBuilder.getBinariesFilePath() == "/usr/local/lib" | ||
contextBuilder.encryptExtraVars() | ||
contextBuilder.getPlaybookPath() == "path/to/playbook" | ||
} | ||
|
||
def "test plugin group not set"(){ | ||
given: | ||
|
||
PluginStepContext context = Mock(PluginStepContext){ | ||
getDataContext() >> ['job': ['loglevel':'INFO']] | ||
getExecutionContext() >> Mock(ExecutionContext){ | ||
getDataContext() >> [:] | ||
} | ||
getFramework() >> Mock(Framework) | ||
getNodes() >> Mock(INodeSet){ | ||
getNodes() >> [] | ||
} | ||
} | ||
|
||
Map<String, Object> configuration = [ | ||
'ansible-playbook' : 'path/to/playbook', | ||
'ansible-config-file-path': '/etc/ansible/ansible.cfg' | ||
] | ||
|
||
when: | ||
AnsibleRunnerContextBuilder contextBuilder = new AnsibleRunnerContextBuilder(context.getExecutionContext(), | ||
context.getFramework(), | ||
context.getNodes(), | ||
configuration, | ||
null) | ||
|
||
then: | ||
contextBuilder.getConfigFile() == "/etc/ansible/ansible.cfg" | ||
contextBuilder.getBinariesFilePath() == null | ||
!contextBuilder.encryptExtraVars() | ||
contextBuilder.getPlaybookPath() == "path/to/playbook" | ||
} | ||
} |