Skip to content

Commit

Permalink
Migrate tests from DynaTest to JUnit5
Browse files Browse the repository at this point in the history
  • Loading branch information
mvysny committed Jan 31, 2025
1 parent 71c035d commit 07e9762
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
71 changes: 71 additions & 0 deletions src/test/kotlin/com/github/vokorm/CockroachDatabaseTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.github.vokorm

import com.gitlab.mvysny.jdbiorm.JdbiOrm
import com.gitlab.mvysny.jdbiorm.quirks.DatabaseVariant
import org.junit.jupiter.api.*
import org.testcontainers.containers.CockroachContainer
import kotlin.test.expect

class CockroachDatabaseTest {
companion object {
private lateinit var container: CockroachContainer
@BeforeAll
@JvmStatic
fun setup() {
assumeDockerAvailable()

container =
CockroachContainer("cockroachdb/cockroach:${DatabaseVersions.cockroach}")
container.start()

hikari {
minimumIdle = 0
maximumPoolSize = 30
jdbcUrl = container.jdbcUrl
username = container.username
password = container.password
}
db {
ddl("""create table if not exists Test (
id bigserial primary key,
name varchar(400) not null,
age integer not null,
dateOfBirth date,
created timestamp,
modified timestamp,
alive boolean,
maritalStatus varchar(200)
)""")
// full-text search not yet supported: https://github.com/cockroachdb/cockroach/issues/41288
// ddl("""CREATE INDEX pgweb_idx ON Test USING GIN (to_tsvector('english', name));""")
ddl("""create table if not exists EntityWithAliasedId(myid bigserial primary key, name varchar(400) not null)""")
ddl("""create table if not exists NaturalPerson(id varchar(10) primary key, name varchar(400) not null, bytes bytea not null)""")
ddl("""create table if not exists LogRecord(id UUID primary key, text varchar(400) not null)""")
ddl("""CREATE TYPE marital_status AS ENUM ('Single', 'Married', 'Widowed', 'Divorced')""")
ddl("""CREATE TABLE IF NOT EXISTS TypeMappingEntity(id bigserial primary key, enumTest marital_status)""")
}
}

@AfterAll
@JvmStatic
fun tearDown() {
JdbiOrm.destroy()
if (::container.isInitialized) {
container.stop()
}
}
}

@BeforeEach @AfterEach fun purgeDb() { clearDb() }

@Test fun `expect PostgreSQL variant`() {
expect(DatabaseVariant.PostgreSQL) {
db {
DatabaseVariant.from(handle)
}
}
}
// full-text search not yet supported: https://github.com/cockroachdb/cockroach/issues/41288
@Nested
inner class AllDatabaseTests : AbstractDatabaseTests(DatabaseInfo(DatabaseVariant.PostgreSQL, supportsFullText = false))
}
2 changes: 1 addition & 1 deletion src/test/kotlin/com/github/vokorm/MssqlDatabaseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MssqlDatabaseTest {
fun setup() {
assumeDockerAvailable()
Assumptions.assumeTrue(isX86_64) { "MSSQL is only available on amd64: https://hub.docker.com/_/microsoft-mssql-server/ " }
Assumptions.assumeTrue(false) { "MSSQL tests fail to run on Github; don't know why, don't care" }
Assumptions.assumeTrue(isWindows) { "MSSQL tests fail to run on GitHub+Linux; don't know why, don't care" }

container =
MSSQLServerContainer("mcr.microsoft.com/mssql/server:${DatabaseVersions.mssql}")
Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/com/github/vokorm/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import java.util.Date
import kotlin.test.expect

val isX86_64: Boolean get() = System.getProperty("os.arch") == "amd64"
val isWindows: Boolean get() = System.getProperty("os.name").contains("Windows", ignoreCase = true)

val gson: Gson = GsonBuilder().registerJavaTimeAdapters().create()

Expand Down

0 comments on commit 07e9762

Please sign in to comment.