-
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.
Fix decoding of data classes in maps, and denormalizing map keys cons…
…istently (#444) Co-authored-by: Oguzhan Soykan <oguzhansoykan@gmail.com>
- Loading branch information
1 parent
6715caf
commit 5967b2f
Showing
12 changed files
with
88 additions
and
48 deletions.
There are no files selected for viewing
33 changes: 0 additions & 33 deletions
33
hoplite-core/src/main/kotlin/com/sksamuel/hoplite/decoder/AbstractUnnormalizedKeysDecoder.kt
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
map: | ||
key1: "test1" | ||
key2: "test2" | ||
key-3: "test3" | ||
Key4: "test4" |
52 changes: 52 additions & 0 deletions
52
hoplite-yaml/src/test/kotlin/com/sksamuel/hoplite/yaml/DenormalizedMapKeysTest.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,52 @@ | ||
package com.sksamuel.hoplite.yaml | ||
|
||
import com.sksamuel.hoplite.ConfigLoaderBuilder | ||
import com.sksamuel.hoplite.addCommandLineSource | ||
import com.sksamuel.hoplite.addResourceOrFileSource | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class DenormalizedMapKeysTest : FunSpec({ | ||
data class Foo( | ||
val xVal: String = "x" | ||
) | ||
|
||
data class MapContainer( | ||
val m: Map<String, Foo> = emptyMap() | ||
) | ||
|
||
test("should set denormalized map keys and decode a data class inside a map") { | ||
val config = ConfigLoaderBuilder.default() | ||
.addResourceOrFileSource("/test_data_class_in_map.yaml") | ||
.build() | ||
.loadConfigOrThrow<MapContainer>() | ||
|
||
config shouldBe MapContainer( | ||
m = mapOf( | ||
"DC1" to Foo("10"), | ||
"DC2" to Foo("20"), | ||
) | ||
) | ||
} | ||
|
||
test("should set denormalized map keys for CLI arguments") { | ||
val config = ConfigLoaderBuilder.default() | ||
.addCommandLineSource( | ||
arrayOf( | ||
"--m.DC1.x-val=10", | ||
"--m.DC2.x-val=20", | ||
), | ||
prefix = "--", | ||
delimiter = "=" | ||
) | ||
.build() | ||
.loadConfigOrThrow<MapContainer>() | ||
|
||
config shouldBe MapContainer( | ||
m = mapOf( | ||
"DC1" to Foo("10"), | ||
"DC2" to Foo("20"), | ||
) | ||
) | ||
} | ||
}) |
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,5 @@ | ||
m: | ||
DC1: | ||
x-val: 10 | ||
DC2: | ||
x-val: 20 |