-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Denormalize maps keys with alternate delimiters (#457)
- Loading branch information
1 parent
502e980
commit 93a0227
Showing
13 changed files
with
97 additions
and
35 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
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
42 changes: 40 additions & 2 deletions
42
hoplite-vavr/src/test/kotlin/com/sksamuel/hoplite/decoder/vavr/MapDecoderTest.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 |
---|---|---|
@@ -1,18 +1,56 @@ | ||
package com.sksamuel.hoplite.decoder.vavr | ||
|
||
import com.sksamuel.hoplite.ConfigLoader | ||
import com.sksamuel.hoplite.sources.EnvironmentVariablesPropertySource | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.vavr.collection.Map | ||
import io.vavr.kotlin.linkedHashMap | ||
|
||
class MapDecoderTest : FunSpec({ | ||
data class Test(val map: Map<String, String>) | ||
|
||
test("Map<String, String> decoded from yaml") { | ||
data class Test(val map: Map<String, String>) | ||
|
||
val config = ConfigLoader().loadConfigOrThrow<Test>("/test_map.yml") | ||
config shouldBe Test(linkedHashMap("key1" to "test1", "key2" to "test2", "key-3" to "test3", "Key4" to "test4")) | ||
} | ||
|
||
test("Map<String, String> decoded from environment with underscores") { | ||
run { | ||
ConfigLoader { | ||
addPropertySource(EnvironmentVariablesPropertySource( | ||
useUnderscoresAsSeparator = true, | ||
allowUppercaseNames = true, | ||
environmentVariableMap = { | ||
mapOf( | ||
"map__key1" to "test1", | ||
"map__key2" to "test2", | ||
"map__key-3" to "test3", | ||
"map__Key4" to "test4", | ||
) | ||
} | ||
)) | ||
}.loadConfigOrThrow<Test>() | ||
} shouldBe Test(linkedHashMap("key1" to "test1", "key2" to "test2", "key-3" to "test3", "Key4" to "test4")) | ||
} | ||
|
||
test("Map<String, String> decoded from environment") { | ||
run { | ||
ConfigLoader { | ||
addPropertySource(EnvironmentVariablesPropertySource( | ||
useUnderscoresAsSeparator = false, | ||
allowUppercaseNames = true, | ||
environmentVariableMap = { | ||
mapOf( | ||
"map.key1" to "test1", | ||
"map.key2" to "test2", | ||
"map.key-3" to "test3", | ||
"map.Key4" to "test4", | ||
) | ||
} | ||
)) | ||
}.loadConfigOrThrow<Test>() | ||
} shouldBe Test(linkedHashMap("key1" to "test1", "key2" to "test2", "key-3" to "test3", "Key4" to "test4")) | ||
} | ||
|
||
}) |
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