
dev.chopsticks.testkit.ManagedSystemProperties.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chopsticks-testkit_2.13 Show documentation
Show all versions of chopsticks-testkit_2.13 Show documentation
Essential Scala libraries for everyday use
package dev.chopsticks.testkit
import com.typesafe.config.ConfigFactory
import zio.{UIO, ZIO, ZManaged}
trait ManagedSystemProperties {
def manageSystemProperties[R, E, A](props: Map[String, String])(use: => ZIO[R, E, A]): ZIO[R, E, A] = {
ZManaged
.make {
UIO {
val _ = sys.props ++= props
ConfigFactory.invalidateCaches()
}
} { _ =>
UIO {
props.keys.foreach(sys.props.remove)
ConfigFactory.invalidateCaches()
}
}.use(_ => use)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy