Skip to content

Commit

Permalink
Added test for checking the not existance of null values in failure d…
Browse files Browse the repository at this point in the history
…ata map
  • Loading branch information
L2JE committed Oct 10, 2023
1 parent 54bdb14 commit c76ee04
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ dependencies {
pluginLibs 'com.google.code.gson:gson:2.10.1'
implementation('org.rundeck:rundeck-core:4.16.0-rc1-20230815')
implementation 'org.codehaus.groovy:groovy-all:3.0.9'

testImplementation platform("org.spockframework:spock-bom:2.0-groovy-3.0")
testImplementation "org.spockframework:spock-core"
}

tasks.withType(Test).configureEach {
useJUnitPlatform()
}

task copyToLib(type: Copy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public void executeNodeStep(
configuration.put(AnsibleDescribable.ANSIBLE_DEBUG,"False");
}

AnsibleRunnerBuilder
builder = new AnsibleRunnerBuilder(context.getExecutionContext(), context.getFramework(), context.getNodes(), configuration);
AnsibleRunnerBuilder builder = new AnsibleRunnerBuilder(context.getExecutionContext(), context.getFramework(), context.getNodes(), configuration);

try {
runner = builder.buildAnsibleRunner();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.rundeck.plugins.ansible.plugin

import com.dtolabs.rundeck.core.common.Framework
import com.dtolabs.rundeck.core.common.INodeEntry
import com.dtolabs.rundeck.core.common.INodeSet
import com.dtolabs.rundeck.core.execution.ExecutionContext
import com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepException
import com.dtolabs.rundeck.plugins.step.NodeStepPlugin
import com.dtolabs.rundeck.plugins.step.PluginStepContext
import org.junit.jupiter.api.Assertions
import spock.lang.Specification


class AnsiblePlaybookInlineWorkflowNodeStepSpec extends Specification{

void "failure data should not include null values when throwing"(){
given:
NodeStepPlugin plugin = new AnsiblePlaybookInlineWorkflowNodeStep()
INodeEntry node = Mock(INodeEntry){
getNodename() >> 'localhost'
}

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'
]

when:
plugin.executeNodeStep(context, configuration, node)

then:
NodeStepException e = thrown(NodeStepException)
e.getFailureData().each { String key, Object value ->
Assertions.assertNotNull(value, "Value for key ${key} should not be null")
}
}
}

0 comments on commit c76ee04

Please sign in to comment.