Skip to content

Commit

Permalink
Add validation and tests for testDir
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengees committed Nov 10, 2021
1 parent 068c535 commit dd6c776
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ val Config.title: String get() = getSafeString(TITLE)
/**
* The path to the directory of the test
*/
val Config.testDir: Path get() = Paths.get(getSafeString(TEST_DIRECTORY))
val Config.testDir: Path get() = FilesUtils.validateExistence(Paths.get(getSafeString(TEST_DIRECTORY)))

/**
* The endpoint to request against.
Expand Down Expand Up @@ -175,7 +175,7 @@ fun Config.withTestDir(testDir: Path): Config = withValue(
*/
fun Config.validate() = this.apply {
// Call getters of properties to check existence and correct declaration.
endpoint; mediaType; shouldExclude; shouldIgnore; headers
endpoint; mediaType; shouldExclude; shouldIgnore; headers; testDir

preProcessors.forEach { checkClass(it) }
preProcessorScripts.forEach { FilesUtils.validateExistence(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.amshove.kluent.shouldThrow
import org.amshove.kluent.withMessage
import org.gradle.api.GradleException
import org.junit.jupiter.api.Test
import java.nio.file.Paths

class ConfigExtensionsTest {

Expand Down Expand Up @@ -82,6 +83,34 @@ class ConfigExtensionsTest {
config.method shouldBeEqualTo "POST"
}

@Test
fun `config object with a valid testDir`() {
val config = ConfigFactory.parseMap(
mapOf(
"endpoint" to "https://example.com",
"testDir" to Paths.get(".").toString()
)
)

val call = { config.validate() }

call shouldNotThrow AnyException
}

@Test
fun `config object with an invalid testDir`() {
val config = ConfigFactory.parseMap(
mapOf(
"endpoint" to "https://example.com",
"testDir" to Paths.get("does_not_exist").toString()
)
)

val call = { config.validate() }

call shouldThrow GradleException::class withMessage "Missing expected file: does_not_exist"
}

@Test
fun `config object with a valid preProcessor`() {
val config = ConfigFactory.parseMap(
Expand Down

0 comments on commit dd6c776

Please sign in to comment.