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:

val preparedService by service.asPrepared()

test("create() should not return null") {
check(preparedService().create() != null)
}

Types

Link copied to clipboard

A scope to combine Arrow's ResourceScope with Prepared's TestDsl.

Functions

Link copied to clipboard

Converts an Arrow Resource into a Prepared value.

Link copied to clipboard
suspend fun <A> TestDsl.install(resource: Resource<A>): A

Installs a Resource into the test's lifecycle scope.

suspend fun <A> TestDsl.install(acquire: suspend TestDsl.() -> A, release: suspend TestDsl.(A, ExitCase) -> Unit): A

Installs an acquire action and its matching release action.

Link copied to clipboard
fun <T> preparedResource(block: suspend TestResourceScope.() -> T): PreparedProvider<T>

Declares a prepared value that contains Arrow Resources.

Link copied to clipboard

Allows accessing the test lifecycle as an Arrow's ResourceScope.