preparedResource

Declares a prepared value that contains Arrow Resources.

The resources are released at the end of the test.

Example

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() }
}

// Note the 'by'!
val service by preparedResource {
Service(dataSource.bind(), userProcessor.bind())
}

test("Some kind of test") {
service().createEntity("…")
}

External resources

See also

Overview of Prepared and Arrow's compatibility.

Convert a Resource into a Prepared value.

Install a Resource directly within a test.