diff --git a/src/main/kotlin/de/smartsquare/squit/config/ConfigExtensions.kt b/src/main/kotlin/de/smartsquare/squit/config/ConfigExtensions.kt index 9ae243f..ee916f4 100644 --- a/src/main/kotlin/de/smartsquare/squit/config/ConfigExtensions.kt +++ b/src/main/kotlin/de/smartsquare/squit/config/ConfigExtensions.kt @@ -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. @@ -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) } diff --git a/src/test/kotlin/de/smartsquare/squit/config/ConfigExtensionsTest.kt b/src/test/kotlin/de/smartsquare/squit/config/ConfigExtensionsTest.kt index b2e7d0a..6c58942 100644 --- a/src/test/kotlin/de/smartsquare/squit/config/ConfigExtensionsTest.kt +++ b/src/test/kotlin/de/smartsquare/squit/config/ConfigExtensionsTest.kt @@ -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 { @@ -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(