From ecbcac81f841f661cc08ed960640599d248f0c89 Mon Sep 17 00:00:00 2001 From: see Date: Fri, 8 Apr 2022 12:34:22 +0200 Subject: [PATCH] added logic for folders and testlogic --- .../domain/{Spec.kt => SyspecConfig.kt} | 7 ++- .../syspec/infrastructure/SyspecConfigRepo.kt | 12 ++--- .../syspec/infrastructure/Verification.kt | 9 +++- .../infrastructure/VerificationKtTest.kt | 48 ++++++++++++++++++- 4 files changed, 65 insertions(+), 11 deletions(-) rename src/main/kotlin/org/domaindrivenarchitecture/provs/syspec/domain/{Spec.kt => SyspecConfig.kt} (89%) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/syspec/domain/Spec.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/syspec/domain/SyspecConfig.kt similarity index 89% rename from src/main/kotlin/org/domaindrivenarchitecture/provs/syspec/domain/Spec.kt rename to src/main/kotlin/org/domaindrivenarchitecture/provs/syspec/domain/SyspecConfig.kt index 7f2edc2..96356d9 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/syspec/domain/Spec.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/syspec/domain/SyspecConfig.kt @@ -3,9 +3,10 @@ package org.domaindrivenarchitecture.provs.syspec.domain import kotlinx.serialization.Serializable @Serializable -data class SpecConfig( +data class SyspecConfig( val command: List? = null, val file: List? = null, + val folder: List? = null, val host: List? = null, val `package`: List? = null, val netcat: List? = null, @@ -13,7 +14,6 @@ data class SpecConfig( val certificate: List? = null, ) - /** * Checks that a command executes successfully and * (if provided) the specified output is contained in the actual output @@ -24,6 +24,9 @@ data class CommandSpec(val command: String, val out: String? = null) @Serializable data class FileSpec(val name: String, val exists: Boolean = true) +@Serializable +data class FolderSpec(val path: String, val exists: Boolean = true) + @Serializable data class HostSpec(val url: String, val expirationDays: Long? = null) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/syspec/infrastructure/SyspecConfigRepo.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/syspec/infrastructure/SyspecConfigRepo.kt index 854716f..3c02b5d 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/syspec/infrastructure/SyspecConfigRepo.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/syspec/infrastructure/SyspecConfigRepo.kt @@ -5,24 +5,24 @@ import org.domaindrivenarchitecture.provs.framework.core.readFromFile import org.domaindrivenarchitecture.provs.framework.core.toYaml import org.domaindrivenarchitecture.provs.framework.core.yamlToType import org.domaindrivenarchitecture.provs.syspec.domain.CommandSpec -import org.domaindrivenarchitecture.provs.syspec.domain.SpecConfig +import org.domaindrivenarchitecture.provs.syspec.domain.SyspecConfig import java.io.File import java.io.FileWriter private const val DEFAULT_CONFIG_FILE = "syspec-config.yaml" // --------------------------------- read ---------------------------------- -internal fun findSpecConfigFromFile(file: ConfigFileName? = null): Result = runCatching { +internal fun findSpecConfigFromFile(file: ConfigFileName? = null): Result = runCatching { val filePath = file?.fileName ?: DEFAULT_CONFIG_FILE if ((filePath == DEFAULT_CONFIG_FILE) && !File(filePath).exists()) { // provide default config - writeSpecConfigToFile(filePath, SpecConfig(listOf(CommandSpec("echo just_for_demo", "just_for_demo")))) + writeSpecConfigToFile(filePath, SyspecConfig(listOf(CommandSpec("echo just_for_demo", "just_for_demo")))) } - readFromFile(filePath).yamlToType() + readFromFile(filePath).yamlToType() } -internal fun findSpecConfigFromResource(resourcePath: String): Result = runCatching { +internal fun findSpecConfigFromResource(resourcePath: String): Result = runCatching { val resource = Thread.currentThread().contextClassLoader.getResource(resourcePath) requireNotNull(resource) { "Resource $resourcePath not found" } resource.readText().yamlToType() @@ -30,5 +30,5 @@ internal fun findSpecConfigFromResource(resourcePath: String): Result