Skip to content

Commit b0b8af9

Browse files
committed
Separated test databases and schemas
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.
1 parent ff48591 commit b0b8af9

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

build.sbt

+7-1
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,15 @@ lazy val doobieUpickleCodecs = module("doobie-upickle") {
251251
lazy val driverTests = module("backend-tests") {
252252
crossProject(JVMPlatform, JSPlatform, NativePlatform)
253253
.crossType(CrossType.Full)
254-
.enablePlugins(NoPublishPlugin)
254+
.enablePlugins(NoPublishPlugin, BuildInfoPlugin)
255255
.dependsOn(postgres)
256256
.settings(
257+
buildInfoKeys := Seq[BuildInfoKey](crossProjectPlatform),
258+
buildInfoPackage := "tests",
259+
buildInfoOptions ++= Seq(
260+
BuildInfoOption.ConstantValue,
261+
BuildInfoOption.PackagePrivate
262+
),
257263
description := "Integration tests for postgres backends",
258264
libraryDependencies ++= Seq(
259265
"org.typelevel" %%% "munit-cats-effect" % Versions.CatsEffectMunit,

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ services:
77
- POSTGRES_PASSWORD=postgres
88
volumes:
99
- ./testdata.sql:/docker-entrypoint-initdb.d/testdata.sql
10+
- ./testdbs.sql:/docker-entrypoint-initdb.d/testdbs.sql
1011
ports:
1112
- 5432:5432

modules/skunk/src/test/scala/SkunkCompatibilitySuite.scala

+28-12
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ class SkunkBinaryCompatibilitySuite
4848

4949
class SkunkPersistenceSuite
5050
extends PersistenceSuite(
51-
backend("skunk_persistence", jsonbCodec),
51+
backendCross("persistence", jsonbCodec),
5252
"skunk"
5353
)
5454

5555
class SkunkPersistenceKeywordNamespaceSuite
5656
extends PersistenceSuite(
57-
backend("order", jsonbCodec),
57+
backend(
58+
"order",
59+
jsonbCodec,
60+
dbName = s"Skunk_${BuildInfo.crossProjectPlatform}"
61+
),
5862
"skunk"
5963
)
6064

@@ -73,23 +77,24 @@ object SkunkCompatibilitySuite {
7377
i => ByteVector.fromHex(i.toString).get.toArray,
7478
a => Either.catchNonFatal(ByteVector(a).toHex.toInt).leftMap(_.getMessage)
7579
)
76-
private val database = Session
80+
private def database(name: String) = Session
7781
.pooled[IO](
78-
"localhost",
79-
5432,
80-
"postgres",
81-
"postgres",
82-
Some("postgres"),
82+
host = "localhost",
83+
port = 5432,
84+
user = "postgres",
85+
database = name.toLowerCase(),
86+
password = Some("postgres"),
8387
4
8488
)
8589

8690
inline def backend(
8791
inline name: String,
88-
codec: BackendCodec[Int]
92+
codec: BackendCodec[Int],
93+
dbName: String = "postgres"
8994
): Resource[IO, Backend[IO, Int, Int, String, Int]] =
9095
given BackendCodec[Int] = codec
9196
import TestDomain.given_ModelTC_State_Event_Rejection
92-
database
97+
database(dbName)
9398
.flatMap(pool =>
9499
Backend
95100
.builder(TestDomainModel)
@@ -99,13 +104,24 @@ object SkunkCompatibilitySuite {
99104
.build
100105
)
101106

102-
inline def backendCqrs(
107+
inline def backendCross(
103108
inline name: String,
104109
codec: BackendCodec[Int]
110+
): Resource[IO, Backend[IO, Int, Int, String, Int]] =
111+
backend(
112+
name + "_" + BuildInfo.crossProjectPlatform,
113+
codec,
114+
s"Skunk_${BuildInfo.crossProjectPlatform}"
115+
)
116+
117+
inline def backendCqrs(
118+
inline name: String,
119+
codec: BackendCodec[Int],
120+
dbName: String = "postgres"
105121
): Resource[IO, cqrs.Backend[IO, Int, String, Int]] =
106122
given BackendCodec[Int] = codec
107123
import TestCQRSModel.given_StateModelTC_State
108-
database
124+
database(dbName)
109125
.flatMap(pool =>
110126
Backend
111127
.builder(TestCQRSDomain)

project/plugins.sbt

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.15.0")
1010
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.2")
1111
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2")
1212
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.17")
13+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")

testdbs.sql

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATE DATABASE Skunk_JVMPlatform;
2+
CREATE DATABASE Skunk_JSPlatform;
3+
CREATE DATABASE Skunk_NativePlatform;
4+
CREATE DATABASE Doobie;

0 commit comments

Comments
 (0)