-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feed ContextResolverMode into decoders
- Loading branch information
Showing
8 changed files
with
68 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
hoplite-core/src/test/kotlin/com/sksamuel/hoplite/resolver/ContextResolverModeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.sksamuel.hoplite.resolver | ||
|
||
import com.sksamuel.hoplite.ConfigLoaderBuilder | ||
import com.sksamuel.hoplite.ExperimentalHoplite | ||
import com.sksamuel.hoplite.parsers.PropsPropertySource | ||
import io.kotest.assertions.throwables.shouldThrowAny | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.string.shouldInclude | ||
import java.util.Properties | ||
|
||
@OptIn(ExperimentalHoplite::class) | ||
class ContextResolverModeTest : FunSpec({ | ||
|
||
data class Config(val bar: String) | ||
|
||
test("should error for unresolved substitutions when context resolver mode is ErrorOnUnresolved") { | ||
|
||
val props = Properties() | ||
props["bar"] = "\${{ ref:foo }}" | ||
|
||
shouldThrowAny { | ||
ConfigLoaderBuilder.newBuilder() | ||
.addPropertySource(PropsPropertySource(props)) | ||
.withContextResolverMode(ContextResolverMode.ErrorOnUnresolved) | ||
.build() | ||
.loadConfigOrThrow<Config>() | ||
}.message shouldInclude "Could not resolve 'foo'" | ||
} | ||
|
||
test("should not error for unresolved substitutions when context resolver mode is SkipUnresolved") { | ||
|
||
val props = Properties() | ||
props["bar"] = "\${{ ref:foo }}" | ||
|
||
val config = ConfigLoaderBuilder.newBuilder() | ||
.addPropertySource(PropsPropertySource(props)) | ||
.withContextResolverMode(ContextResolverMode.SkipUnresolved) | ||
.build() | ||
.loadConfigOrThrow<Config>() | ||
|
||
config shouldBe Config(bar = "\${{ ref:foo }}") | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters