Skip to content

Compatibility with Arrowopensavvy.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:

val preparedService by service.asPrepared()

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

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

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.

preparedResource

fun <T> preparedResource(block: suspend TestResourceScope.() -> T): PreparedProvider<T>

Declares a prepared value that contains Arrow Resources.

resourceScope

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