Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #57 now EnvironmentCL uses also the properties.
- Loading branch information
Showing
6 changed files
with
84 additions
and
36 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
15 changes: 15 additions & 0 deletions
15
cfg4k-core/src/test/kotlin/com/jdiazcano/cfg4k/TestUtils.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,15 @@ | ||
package com.jdiazcano.cfg4k | ||
|
||
internal fun setEnv(key: String, value: String) { | ||
try { | ||
val env = System.getenv() | ||
val cl = env.javaClass | ||
val field = cl.getDeclaredField("m") | ||
field.isAccessible = true | ||
val writableEnv = field.get(env) as MutableMap<String, String> | ||
writableEnv.put(key, value) | ||
} catch (e: Exception) { | ||
throw IllegalStateException("Failed to set environment variable", e) | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
cfg4k-core/src/test/kotlin/com/jdiazcano/cfg4k/loaders/EnvironmentConfigLoaderTest.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,51 @@ | ||
package com.jdiazcano.cfg4k.loaders | ||
|
||
import com.jdiazcano.cfg4k.core.toConfig | ||
import com.jdiazcano.cfg4k.providers.* | ||
import com.winterbe.expekt.should | ||
import io.mockk.every | ||
import io.mockk.mockkStatic | ||
import io.mockk.unmockkAll | ||
import org.jetbrains.spek.api.Spek | ||
import org.jetbrains.spek.api.dsl.describe | ||
import org.jetbrains.spek.api.dsl.it | ||
|
||
class EnvironmentConfigLoaderTest : Spek({ | ||
|
||
describe("a property config loader") { | ||
mockkStatic(System::class) | ||
every { System.getenv() } returns mapOf( | ||
"PROPERTIES_GROUPONE_KEYONE" to "1", | ||
"PROPERTIES_GROUPONE_KEYTWO" to "2" | ||
) | ||
|
||
val loader = EnvironmentConfigLoader() | ||
val provider = ProxyConfigProvider(loader) | ||
|
||
it("it should be good in the loader") { | ||
loader.get("properties.groupone.keyone").should.be.equal("1".toConfig()) | ||
} | ||
|
||
it ("should be also good with the provider") { | ||
provider.get<String>("properties.groupone.keyone").should.be.equal("1") | ||
} | ||
|
||
it("works with binding") { | ||
val properties = provider.bind<Props>("properties") | ||
properties.groupone.keyone.should.be.equal("1") | ||
properties.groupone.keytwo.should.be.equal("2") | ||
} | ||
|
||
unmockkAll() | ||
} | ||
|
||
}) | ||
|
||
interface Props { | ||
val groupone: Groupone | ||
} | ||
|
||
interface Groupone { | ||
val keyone: String | ||
val keytwo: String | ||
} |
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