-
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
1 parent
83a4224
commit 0abe20d
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/test/groovy/com/rundeck/plugins/ansible/util/AnsibleUtilSpec.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,63 @@ | ||
package com.rundeck.plugins.ansible.util | ||
|
||
import com.dtolabs.rundeck.core.common.Framework | ||
import com.dtolabs.rundeck.core.utils.PropertyLookup | ||
import spock.lang.Specification | ||
import spock.lang.TempDir | ||
|
||
import java.nio.file.Files | ||
|
||
class AnsibleUtilSpec extends Specification{ | ||
|
||
@TempDir | ||
File tempDir | ||
|
||
def "createTemporaryFile should create a temporary file with the correct properties"() { | ||
given: "Input parameters for the temporary file" | ||
String prefix = inputPrefix | ||
String suffix = ".txt" | ||
String data = "test data" | ||
String path = tempDir.absolutePath | ||
|
||
when: "The method is called" | ||
File result = AnsibleUtil.createTemporaryFile(prefix, suffix, data, path) | ||
|
||
then: "The file is created in the specified path with the correct content" | ||
result.exists() | ||
result.parent == tempDir.absolutePath | ||
result.name.startsWith(expectedPrefix) | ||
result.name.endsWith(suffix) | ||
new String(Files.readAllBytes(result.toPath())) == data | ||
|
||
where: | ||
inputPrefix || expectedPrefix | ||
"my-prefix" || "my-prefix" | ||
"" || "ansible-runner" | ||
} | ||
|
||
def "getCustomTmpPathDir should return the correct tmp path based on framework properties"() { | ||
given: "A mock Framework and PropertyLookup" | ||
def framework = Mock(Framework) | ||
def propertyLookup = Mock(PropertyLookup) | ||
framework.getPropertyLookup() >> propertyLookup | ||
|
||
and: "A specific value for framework.tmp.dir property" | ||
propertyLookup.getProperty("framework.tmp.dir") >> frameworkTmpDir | ||
|
||
and: "A system property for java.io.tmpdir" | ||
System.setProperty("java.io.tmpdir", systemTmpDir) | ||
|
||
when: "The method is called" | ||
def result = AnsibleUtil.getCustomTmpPathDir(framework) | ||
|
||
then: "The expected tmp path is returned" | ||
result == expectedTmpDir | ||
|
||
where: | ||
frameworkTmpDir | systemTmpDir || expectedTmpDir | ||
"custom/tmp/dir" | "/default/tmp" || "custom/tmp/dir" // Case where framework.tmp.dir is set | ||
"" | "/default/tmp" || "/default/tmp" // Case where framework.tmp.dir is empty | ||
null | "/default/tmp" || "/default/tmp" // Case where framework.tmp.dir is null | ||
} | ||
} | ||
|