Skip to content

strict() mode fails because of the environment variables. #505

@jhoarau-grindr

Description

@jhoarau-grindr

strict() mode fails because of the environment variables.

Test case:

class CreateConfigTest : FunSpec({

   data class TestConfig(
      val name: String,
   )

   test("strict() should ignore environment variables") {
      val config = ConfigLoaderBuilder.default()
         .addMapSource(mapOf("name" to "test"))
         .strict()
         .build()
         .loadConfigOrThrow<TestConfig>()

      config.name shouldBe "test"
   }
})

Expected output:

Test should pass

Actual output:

Test fails with error:

Error loading config because:
com.sksamuel.hoplite.ConfigException: Error loading config because:

    Config value '' at (env) was unused

    Config value '_' at (env) was unused

    ... (Cut for brevity)

    Config value 'USER' at (env) was unused

    Config value 'ZSH' at (env) was unused

    Config value 'TMPDIR' at (env) was unused

    Config value 'PYENV' at (env) was unused

    Config value 'PYENV_SHELL' at (env) was unused

    Config value 'PYENV_ROOT' at (env) was unused

    Config value 'LC' at (env) was unused

    Config value 'LC_CTYPE' at (env) was unused

    Config value 'LESS' at (env) was unused

    Config value 'HOME' at (env) was unused
	at com.sksamuel.hoplite.ConfigLoaderKt$returnOrThrow$1.invoke(ConfigLoader.kt:354)
	at com.sksamuel.hoplite.ConfigLoaderKt$returnOrThrow$1.invoke(ConfigLoader.kt:351)
	at com.sksamuel.hoplite.fp.ValidatedKt.getOrElse(Validated.kt:115)
	at com.sksamuel.hoplite.ConfigLoaderKt.returnOrThrow(ConfigLoader.kt:351)
	at com.sksamuel.hoplite.ConfigLoader.returnOrThrow(ConfigLoader.kt:312)
	at com.grindr.accelerator.app.CreateConfigTest$1$1.invokeSuspend(CreateConfigTest.kt:31)
	at com.grindr.accelerator.app.CreateConfigTest$1$1.invoke(CreateConfigTest.kt)
	at com.grindr.accelerator.app.CreateConfigTest$1$1.invoke(CreateConfigTest.kt)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions