Skip to content

Commit

Permalink
Separated test databases and schemas
Browse files Browse the repository at this point in the history
Test databases and schemas are separated by lib/platform
This ensures that when running all tests together, each test suite is
isolated and doesn't have an impact on other test suites.
  • Loading branch information
hnaderi committed Jan 22, 2024
1 parent ff48591 commit b0b8af9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
8 changes: 7 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,15 @@ lazy val doobieUpickleCodecs = module("doobie-upickle") {
lazy val driverTests = module("backend-tests") {
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.enablePlugins(NoPublishPlugin)
.enablePlugins(NoPublishPlugin, BuildInfoPlugin)
.dependsOn(postgres)
.settings(
buildInfoKeys := Seq[BuildInfoKey](crossProjectPlatform),
buildInfoPackage := "tests",
buildInfoOptions ++= Seq(
BuildInfoOption.ConstantValue,
BuildInfoOption.PackagePrivate
),
description := "Integration tests for postgres backends",
libraryDependencies ++= Seq(
"org.typelevel" %%% "munit-cats-effect" % Versions.CatsEffectMunit,
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ services:
- POSTGRES_PASSWORD=postgres
volumes:
- ./testdata.sql:/docker-entrypoint-initdb.d/testdata.sql
- ./testdbs.sql:/docker-entrypoint-initdb.d/testdbs.sql
ports:
- 5432:5432
40 changes: 28 additions & 12 deletions modules/skunk/src/test/scala/SkunkCompatibilitySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ class SkunkBinaryCompatibilitySuite

class SkunkPersistenceSuite
extends PersistenceSuite(
backend("skunk_persistence", jsonbCodec),
backendCross("persistence", jsonbCodec),
"skunk"
)

class SkunkPersistenceKeywordNamespaceSuite
extends PersistenceSuite(
backend("order", jsonbCodec),
backend(
"order",
jsonbCodec,
dbName = s"Skunk_${BuildInfo.crossProjectPlatform}"
),
"skunk"
)

Expand All @@ -73,23 +77,24 @@ object SkunkCompatibilitySuite {
i => ByteVector.fromHex(i.toString).get.toArray,
a => Either.catchNonFatal(ByteVector(a).toHex.toInt).leftMap(_.getMessage)
)
private val database = Session
private def database(name: String) = Session
.pooled[IO](
"localhost",
5432,
"postgres",
"postgres",
Some("postgres"),
host = "localhost",
port = 5432,
user = "postgres",
database = name.toLowerCase(),
password = Some("postgres"),
4
)

inline def backend(
inline name: String,
codec: BackendCodec[Int]
codec: BackendCodec[Int],
dbName: String = "postgres"
): Resource[IO, Backend[IO, Int, Int, String, Int]] =
given BackendCodec[Int] = codec
import TestDomain.given_ModelTC_State_Event_Rejection
database
database(dbName)
.flatMap(pool =>
Backend
.builder(TestDomainModel)
Expand All @@ -99,13 +104,24 @@ object SkunkCompatibilitySuite {
.build
)

inline def backendCqrs(
inline def backendCross(
inline name: String,
codec: BackendCodec[Int]
): Resource[IO, Backend[IO, Int, Int, String, Int]] =
backend(
name + "_" + BuildInfo.crossProjectPlatform,
codec,
s"Skunk_${BuildInfo.crossProjectPlatform}"
)

inline def backendCqrs(
inline name: String,
codec: BackendCodec[Int],
dbName: String = "postgres"
): Resource[IO, cqrs.Backend[IO, Int, String, Int]] =
given BackendCodec[Int] = codec
import TestCQRSModel.given_StateModelTC_State
database
database(dbName)
.flatMap(pool =>
Backend
.builder(TestCQRSDomain)
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.15.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.2")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.17")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
4 changes: 4 additions & 0 deletions testdbs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE DATABASE Skunk_JVMPlatform;
CREATE DATABASE Skunk_JSPlatform;
CREATE DATABASE Skunk_NativePlatform;
CREATE DATABASE Doobie;

0 comments on commit b0b8af9

Please sign in to comment.