add spec from resource
This commit is contained in:
parent
5f897a3be5
commit
df124f0c25
5 changed files with 83 additions and 4 deletions
|
@ -106,7 +106,7 @@ publish-snapshot-lib:
|
|||
rules:
|
||||
- if: $CI_PIPELINE_SOURCE != "push"
|
||||
when: never
|
||||
- if: $CI_COMMIT_TAG !~ /^[0-9]+[.][0-9]+([.][0-9]+-SNAPSHOT)?$/
|
||||
- if: $CI_COMMIT_TAG !~ /^release-[0-9]+[.][0-9]+([.][0-9]+)?$/
|
||||
script:
|
||||
- ./gradlew -x assemble -x test jar
|
||||
- ./gradlew -x assemble -x test publish
|
||||
|
|
|
@ -4,14 +4,27 @@ import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
|
|||
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
||||
import org.domaindrivenarchitecture.provs.syspec.infrastructure.findSpecConfigFromFile
|
||||
import org.domaindrivenarchitecture.provs.syspec.infrastructure.findSpecConfigFromResource
|
||||
import org.domaindrivenarchitecture.provs.syspec.infrastructure.verifySpecConfig
|
||||
|
||||
|
||||
fun Prov.verifySpec(config: ConfigFileName?) = task {
|
||||
val spec = findSpecConfigFromFile(config)
|
||||
fun Prov.verifySpec(configFile: ConfigFileName? = null) = task {
|
||||
val spec = findSpecConfigFromFile(configFile)
|
||||
|
||||
if (spec == null) {
|
||||
ProvResult(false, "Could not read file: ${config?.fileName}")
|
||||
ProvResult(false, "Could not read file: ${configFile?.fileName}")
|
||||
} else {
|
||||
verifySpecConfig(spec)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Suppress("unused") // Api
|
||||
fun Prov.verifySpecFromResource(resourceName: String) = task {
|
||||
val spec = findSpecConfigFromResource(resourceName)
|
||||
|
||||
if (spec == null) {
|
||||
ProvResult(false, "Could not read resource: ${resourceName}")
|
||||
} else {
|
||||
verifySpecConfig(spec)
|
||||
}
|
||||
|
|
|
@ -45,3 +45,19 @@ internal fun findSpecConfigFromFile(file: ConfigFileName? = null): SpecConfig? {
|
|||
null
|
||||
}
|
||||
}
|
||||
|
||||
internal fun getSpecConfigFromResource(resourcePath: String): SpecConfig {
|
||||
val resource = Thread.currentThread().contextClassLoader.getResource(resourcePath)
|
||||
requireNotNull(resource) { "Resource $resourcePath not found" }
|
||||
return resource.readText().yamlToType()
|
||||
}
|
||||
|
||||
internal fun findSpecConfigFromResource(resourcePath: String): SpecConfig? {
|
||||
return try {
|
||||
val config = getSpecConfigFromResource(resourcePath)
|
||||
config
|
||||
} catch (e: IllegalArgumentException) {
|
||||
println("Error: " + e.message)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package org.domaindrivenarchitecture.provs.syspec.infrastructure
|
||||
|
||||
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
|
||||
import org.domaindrivenarchitecture.provs.syspec.domain.CommandSpec
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
internal class SyspecConfigRepoKtTest {
|
||||
|
||||
@Test
|
||||
fun getSpecConfigFromFile_success() {
|
||||
// when
|
||||
@Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") // null would reveal test error
|
||||
val filePath = javaClass.classLoader.getResource("syspec-config.yaml").file
|
||||
val res = getSpecConfigFromFile(ConfigFileName(filePath))
|
||||
|
||||
// then
|
||||
assertEquals(listOf(CommandSpec("echo just_for_test", "just_for_test")), res.command)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSpecConfigFromResource_success() {
|
||||
// when
|
||||
val res = getSpecConfigFromResource("syspec-config.yaml")
|
||||
|
||||
// then
|
||||
assertEquals(listOf(CommandSpec("echo just_for_test", "just_for_test")), res.command)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findSpecConfigFromFile_null() {
|
||||
// when
|
||||
val res = findSpecConfigFromFile(ConfigFileName("dontexist"))
|
||||
|
||||
// then
|
||||
assertNull(res)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findSpecConfigFromResource_null() {
|
||||
// when
|
||||
val res = findSpecConfigFromResource("dontexist")
|
||||
|
||||
// then
|
||||
assertNull(res)
|
||||
}
|
||||
}
|
3
src/test/resources/syspec-config.yaml
Normal file
3
src/test/resources/syspec-config.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
command:
|
||||
- command: "echo just_for_test"
|
||||
out: "just_for_test"
|
Loading…
Reference in a new issue