zio / zio-config

Easily use and document any config from anywhere in ZIO apps
https://zio.dev/zio-config
Apache License 2.0
233 stars 113 forks source link

Support TestSystem in Typesafe Config provider #1241

Open przemek-pokrywka opened 1 year ago

przemek-pokrywka commented 1 year ago

Until #1053 gets completed, the TestSystem is basically ignored in the integration with Typesafe Config.

Even though the external library does not support overriding of the System class method calls, there would be a way around this. Both system properties and the environment variables can be altered globally (the latter using a reflection hack), so the only remaining part is to assure, that all Typesafe Config reads are done sequentially - which should be possible using a JVM-global semaphore.

This would unblock testing of how do the environment variables resolve to the configuration values in complex cases.

Another advantage of the proposal is that it's safer for legacy apps (which use complex HOCON configurations already) since all the undocumented quirks of the 3rd party library would work as before. That would make it less risky to port them to ZIO.

przemek-pokrywka commented 1 year ago

Would anyone be interested in a PR with the changes described above?

przemek-pokrywka commented 1 year ago

Both system properties and the environment variables can be altered globally (the latter using a reflection hack)

Since the hack will only work on certain JVMs, the code would need to check if using it is possible, and if not, then a descriptive exception should be thrown.