Compatibility with Arrow • opensavvy.prepared.compat.arrow.coroutines
Package-level declarations¶
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>
Converts an Arrow Resource into a Prepared value.
install¶
Installs a Resource into the test's lifecycle scope.
preparedResource¶
fun <T> preparedResource(block: suspend TestResourceScope.() -> T): PreparedProvider<T>
Declares a prepared value that contains Arrow Resources.
resourceScope¶
fun TestDsl.resourceScope(): TestResourceScope
Allows accessing the test lifecycle as an Arrow's ResourceScope.