You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to avoid using ConfigSpec classes, and instead use the toValue() function to instantiate configuration directly into target classes. For the case where I want to grab a single property, this works fine if the config files I'm loading from all contain all the property I'm looking for, but if any of them don't, it errors. e.g. relevant snippets from the linked test case:
config1.conf:
server {
host = "0.0.0.0"
}
config2-missing-host.conf:
server {
# if i uncomment the host here, things work as expected.
# host = "1.1.1.1"
}
test:
packagequestionimportcom.uchuhimo.konf.Configimportcom.uchuhimo.konf.source.hoconimportcom.uchuhimo.konf.toValueimportio.kotest.matchers.shouldBeimportorg.junit.jupiter.api.TestclassConfigTest {
data classServerConfig(valhost:String)
@Test
fun`foo hocon`() {
val config =Config()
.from.hocon.resource("config1.conf")
.from.hocon.resource("config2-missing-host.conf", optional =true)
val serverConfig = config.at("server").toValue<ServerConfig>()
serverConfig.host shouldBe "0.0.0.0"/* The following line throws: item root is unset com.uchuhimo.konf.UnsetValueException: item root is unset at app//com.uchuhimo.konf.BaseConfig.getOrNull(BaseConfig.kt:187) at app//com.uchuhimo.konf.BaseConfig.getOrNull$default(BaseConfig.kt:179) at app//com.uchuhimo.konf.BaseConfig.get(BaseConfig.kt:159) at app//com.uchuhimo.konf.BaseConfig$property$1.getValue(BaseConfig.kt:527)*/val host = config.at("server.host").toValue<String>()
host shouldBe "0.0.0.0"
}
}
Is there a different/better way to get at individual properties and objects without using Spec files? Or is this reasonable to work as expected? Thanks.
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.
Test case here: https://github.com/dtanner/konf-question/blob/get_at_question/src/test/kotlin/question/ConfigTest.kt#L32
I'd like to avoid using ConfigSpec classes, and instead use the
toValue()
function to instantiate configuration directly into target classes. For the case where I want to grab a single property, this works fine if the config files I'm loading from all contain all the property I'm looking for, but if any of them don't, it errors. e.g. relevant snippets from the linked test case:config1.conf:
config2-missing-host.conf:
test:
Is there a different/better way to get at individual properties and objects without using Spec files? Or is this reasonable to work as expected? Thanks.
The text was updated successfully, but these errors were encountered: