-
Notifications
You must be signed in to change notification settings - Fork 88
Closed
Description
Problem Statement
kyo-zio-test could benefit from two improvements:
- The ability to use the Environment in Kyo-zio-test
- The ability to provide (and provideX variants) Kyo Layers to specs & tests to eliminate the Environment dependency
Proposed Solution
The ideal API could look like this
object PgKyoSpec extends KyoSpecDefault:
def spec = suite("Postgres Magnum Kyo tests")(
test("count") {
Env.use[TransactorKyo] {
_.connect:
carRepo.count
.map(result => assertTrue(result == 3L))
}
},
test("another one")(...)
).provideShared(transactorKyoLayer) // transactorKyoLayer is Layer[TransactorKyo, Resource & IO]The above layer would instantiate the transactor kyo layer once and reuse it across all tests
Alternative Solutions
No response
Current Workaround
One could extend KyoSpecAbstract and provide layers manually but you don't get the benefits of memoization:
import kyo.*
import zio.ZIO
import kyo.test.*
import com.augustnagro.magnum.magkyo.TransactorKyo
import zio.test.Spec
import com.dimafeng.testcontainers.PostgreSQLContainer
import org.testcontainers.utility.DockerImageName
import org.postgresql.ds.PGSimpleDataSource
import java.nio.file.{Files, Path}
import com.augustnagro.magnum.SqlLogger
abstract class KyoSpecMagnum
extends KyoSpecAbstract[
Async & Resource & Abort[Throwable] & Env[TransactorKyo]
]:
final override def run[In](
v: => In < (Async & Resource & Abort[Throwable] & Env[TransactorKyo])
)(using
Frame
): ZIO[Environment, Throwable, In] =
ZIOs.run {
Memo.run {
Resource.run {
Env.runLayer( Layer(transactorKyo)) {
v
}
}
}
}
private def transactorKyo: TransactorKyo < (Resource & IO) = ...Additional Context
This ask came when trying to write tests for the Magnum Kyo integration
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels