forked from zio/zio-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestContainer.scala
37 lines (32 loc) · 1005 Bytes
/
TestContainer.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package zio.sql
import com.dimafeng.testcontainers.SingleContainer
import com.dimafeng.testcontainers.MSSQLServerContainer
import org.testcontainers.utility.DockerImageName
import zio._
import zio.blocking.{ effectBlocking, Blocking }
object TestContainer {
def container[C <: SingleContainer[_]: Tag](c: C): ZLayer[Blocking, Throwable, Has[C]] =
ZManaged.make {
effectBlocking {
c.start()
c
}
}(container => effectBlocking(container.stop()).orDie).toLayer
def postgres(
imageName: String = "mcr.microsoft.com/mssql/server:2017-latest"
): ZLayer[Blocking, Throwable, Has[MSSQLServerContainer]] =
ZManaged.make {
effectBlocking {
val c = new MSSQLServerContainer(
dockerImageName = DockerImageName.parse(imageName)
).configure { a =>
a.withInitScript("db_schema.sql")
()
}
c.start()
c
}
} { container =>
effectBlocking(container.stop()).orDie
}.toLayer
}