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 6512f2f commit f5ec703
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 312 deletions.
70 changes: 0 additions & 70 deletions src/test/kotlin/com/github/vokorm/AllDatabaseTests.kt

This file was deleted.

242 changes: 0 additions & 242 deletions src/test/kotlin/com/github/vokorm/Databases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,152 +110,15 @@ private fun DynaNodeGroup.usingDockerizedPosgresql() {
afterEach { clearDb() }
}

@DynaTestDsl
private fun DynaNodeGroup.usingDockerizedCockroachDB() {
check(DockerClientFactory.instance().isDockerAvailable()) { "Docker not available" }
lateinit var container: CockroachContainer
beforeGroup {
container = CockroachContainer("cockroachdb/cockroach:${DatabaseVersions.cockroach}")
container.start()
}
beforeGroup {
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)""")
}
}

afterGroup { JdbiOrm.destroy() }
afterGroup { container.stop() }

beforeEach { clearDb() }
afterEach { clearDb() }
}

@DynaTestDsl
fun DynaNodeGroup.usingDockerizedMysql() {
check(DockerClientFactory.instance().isDockerAvailable()) { "Docker not available" }
lateinit var container: MySQLContainer<*>
beforeGroup {
container = MySQLContainer("mysql:${DatabaseVersions.mysql}")
// disable SSL, to avoid SSL-related exceptions on github actions:
// javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
container.withUrlParam("useSSL", "false")
container.start()
}
beforeGroup {
hikari {
minimumIdle = 0
maximumPoolSize = 30
jdbcUrl = container.jdbcUrl
username = container.username
password = container.password
}
db {
ddl("""create table if not exists Test (
id bigint primary key auto_increment,
name varchar(400) not null,
age integer not null,
dateOfBirth date,
created timestamp(3) NULL,
modified timestamp(3) NULL,
alive boolean,
maritalStatus varchar(200),
FULLTEXT index (name)
)""")
ddl("""create table if not exists EntityWithAliasedId(myid bigint primary key auto_increment, name varchar(400) not null)""")
ddl("""create table if not exists NaturalPerson(id varchar(10) primary key, name varchar(400) not null, bytes binary(16) not null)""")
ddl("""create table if not exists LogRecord(id binary(16) primary key, text varchar(400) not null)""")
ddl("""create table TypeMappingEntity(id bigint primary key auto_increment, enumTest ENUM('Single', 'Married', 'Divorced', 'Widowed'))""")
}
}

afterGroup { JdbiOrm.destroy() }
afterGroup { container.stop() }

beforeEach { clearDb() }
afterEach { clearDb() }
}

fun hikari(block: HikariConfig.() -> Unit) {
JdbiOrm.databaseVariant = null
JdbiOrm.setDataSource(HikariDataSource(HikariConfig().apply(block)))
}

@DynaTestDsl
fun DynaNodeGroup.usingH2Database() {
}

fun PersistenceContext.ddl(@Language("sql") sql: String) {
handle.execute(sql)
}

@DynaTestDsl
private fun DynaNodeGroup.usingDockerizedMariaDB() {
check(DockerClientFactory.instance().isDockerAvailable()) { "Docker not available" }
lateinit var container: MariaDBContainer<*>
beforeGroup {
container = MariaDBContainer("mariadb:${DatabaseVersions.mariadb}")
container.start()
}
beforeGroup {
hikari {
minimumIdle = 0
maximumPoolSize = 30
jdbcUrl = container.jdbcUrl
username = container.username
password = container.password
}
db {
ddl(
"""create table if not exists Test (
id bigint primary key auto_increment,
name varchar(400) not null,
age integer not null,
dateOfBirth date,
created timestamp(3) NULL,
modified timestamp(3) NULL,
alive boolean,
maritalStatus varchar(200),
FULLTEXT index (name)
)"""
)
ddl("""create table if not exists EntityWithAliasedId(myid bigint primary key auto_increment, name varchar(400) not null)""")
ddl("""create table if not exists NaturalPerson(id varchar(10) primary key, name varchar(400) not null, bytes binary(16) not null)""")
ddl("""create table if not exists LogRecord(id binary(16) primary key, text varchar(400) not null)""")
ddl("""create table TypeMappingEntity(id bigint primary key auto_increment, enumTest ENUM('Single', 'Married', 'Divorced', 'Widowed'))""")
}
}

afterGroup { JdbiOrm.destroy() }
afterGroup { container.stop() }

beforeEach { clearDb() }
afterEach { clearDb() }
}

fun clearDb() {
Person.deleteAll()
EntityWithAliasedId.deleteAll()
Expand All @@ -264,109 +127,4 @@ fun clearDb() {
TypeMappingEntity.deleteAll()
}

@DynaTestDsl
private fun DynaNodeGroup.usingDockerizedMSSQL() {
check(DockerClientFactory.instance().isDockerAvailable()) { "Docker not available" }
check(isX86_64) { "MSSQL is only available on amd64: https://hub.docker.com/_/microsoft-mssql-server/ "}
lateinit var container: MSSQLServerContainer<*>
beforeGroup {
container = MSSQLServerContainer("mcr.microsoft.com/mssql/server:${DatabaseVersions.mssql}")
container.start()
}
beforeGroup {
hikari {
minimumIdle = 0
maximumPoolSize = 30
jdbcUrl = container.jdbcUrl
username = container.username
password = container.password
}
db {
// otherwise the CREATE FULLTEXT CATALOG would fail: Cannot use full-text search in master, tempdb, or model database.
ddl("CREATE DATABASE foo")
ddl("USE foo")
ddl("CREATE FULLTEXT CATALOG AdvWksDocFTCat")

ddl(
"""create table Test (
id bigint primary key IDENTITY(1,1) not null,
name varchar(400) not null,
age integer not null,
dateOfBirth datetime,
created datetime NULL,
modified datetime NULL,
alive bit,
maritalStatus varchar(200)
)"""
)
// unfortunately the default Docker image doesn't support the FULLTEXT index:
// https://stackoverflow.com/questions/60489784/installing-mssql-server-express-using-docker-with-full-text-search-support
// just skip the tests for now
/*
ddl("CREATE UNIQUE INDEX ui_ukDoc ON Test(name);")
ddl("""CREATE FULLTEXT INDEX ON Test
(
Test --Full-text index column name
TYPE COLUMN name --Name of column that contains file type information
Language 2057 --2057 is the LCID for British English
)
KEY INDEX ui_ukDoc ON AdvWksDocFTCat --Unique index
WITH CHANGE_TRACKING AUTO --Population type; """)
*/

ddl("""create table EntityWithAliasedId(myid bigint primary key IDENTITY(1,1) not null, name varchar(400) not null)""")
ddl("""create table NaturalPerson(id varchar(10) primary key not null, name varchar(400) not null, bytes binary(16) not null)""")
ddl("""create table LogRecord(id uniqueidentifier primary key not null, text varchar(400) not null)""")
ddl("""create table TypeMappingEntity(id bigint primary key IDENTITY(1,1) not null, enumTest varchar(10))""")
}
}

afterGroup { JdbiOrm.destroy() }
afterGroup { container.stop() }

beforeEach { clearDb() }
afterEach { clearDb() }
}

@DynaTestDsl
fun DynaNodeGroup.withAllDatabases(block: DynaNodeGroup.(DatabaseInfo)->Unit) {
if (System.getProperty("h2only").toBoolean()) {
println("`h2only` system property specified, skipping PostgreSQL/MySQL/MariaDB/MSSQL tests")
} else if (!DockerClientFactory.instance().isDockerAvailable) {
println("Docker is not available, not running PostgreSQL/MySQL/MariaDB/MSSQL tests")
} else {
println("Docker is available, running PostgreSQL/MySQL/MariaDB tests")
group("PostgreSQL ${DatabaseVersions.postgres}") {
usingDockerizedPosgresql()
block(DatabaseInfo(DatabaseVariant.PostgreSQL))
}

group("MySQL ${DatabaseVersions.mysql}") {
usingDockerizedMysql()
block(DatabaseInfo(DatabaseVariant.MySQLMariaDB))
}

group("MariaDB ${DatabaseVersions.mariadb}") {
usingDockerizedMariaDB()
block(DatabaseInfo(DatabaseVariant.MySQLMariaDB))
}

// MSSQL tests fail on GitHub Linux runners. Don't know why, don't care.
if (isX86_64 && false) {
group("MSSQL ${DatabaseVersions.mssql}") {
usingDockerizedMSSQL()
// unfortunately the default Docker image doesn't support the FULLTEXT index:
// https://stackoverflow.com/questions/60489784/installing-mssql-server-express-using-docker-with-full-text-search-support
block(DatabaseInfo(DatabaseVariant.MSSQL, supportsFullText = false))
}
}

group("CockroachDB ${DatabaseVersions.cockroach}") {
usingDockerizedCockroachDB()
// full-text search not yet supported: https://github.com/cockroachdb/cockroach/issues/41288
block(DatabaseInfo(DatabaseVariant.PostgreSQL, supportsFullText = false))
}
}
}

data class DatabaseInfo(val variant: DatabaseVariant, val supportsFullText: Boolean = true)

0 comments on commit f5ec703

Please sign in to comment.