opensavvy.prepared.compat.arrow.coroutines¶
Helpers to use Arrow's Resource DSL in tests.
Let's assume that we want to test a service we own that is already encapsulated in a resource within your production code:
val userProcessor: Resource<UserProcessor> = resource({
UserProcessor().also { it.start() }
}) { p, _ -> p.shutdown() }
val dataSource: Resource<DataSource> = resource({
DataSource().also { it.connect() }
}) { ds, exitCase ->
println("Releasing $ds with exit: $exitCase")
withContext(Dispatchers.IO) { ds.close() }
}
val service: Resource<Service> = resource {
Service(dataSource.bind(), userProcessor.bind())
}
We can use asPrepared to convert that resource into Prepared's native prepared values:
Types¶
TestResourceScope¶
interface TestResourceScope : ResourceScope, TestDsl
A scope to combine Arrow's ResourceScope with Prepared's TestDsl.
Functions¶
asPrepared¶
fun <T> Resource<T>.asPrepared(): PreparedProvider<T>
preparedResource¶
fun <T> preparedResource(block: suspend TestResourceScope.() -> T): PreparedProvider<T>
Declares a prepared value that contains Arrow Resources.