Merge pull request #1026 from eikek/migration-tests

Test db migrations for all supported databases
This commit is contained in:
mergify[bot] 2021-08-23 21:53:51 +00:00 committed by GitHub
commit 945ca6f561
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 119 additions and 1 deletions

View File

@ -353,7 +353,9 @@ val store = project
Dependencies.emil ++
Dependencies.emilDoobie ++
Dependencies.calevCore ++
Dependencies.calevFs2
Dependencies.calevFs2,
libraryDependencies ++=
Dependencies.testContainer.map(_ % Test)
)
.dependsOn(common, query.jvm)

View File

@ -0,0 +1,19 @@
/*
* Copyright 2020 Docspell Contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package docspell.store.migrate
import cats.effect._
import cats.effect.unsafe.implicits._
object Docker {
def exists: IO[Boolean] =
IO(Runtime.getRuntime.exec(Array("docker", "--version")).waitFor() == 0).attempt
.map(_.fold(_ => false, identity))
def existsUnsafe: Boolean =
exists.unsafeRunSync()
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2020 Docspell Contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package docspell.store.migrate
import cats.effect.IO
import cats.effect.unsafe.implicits._
import docspell.store.StoreFixture
import munit.FunSuite
class H2MigrateTest extends FunSuite {
test("h2 empty schema migration") {
val jdbc = StoreFixture.memoryDB("h2test")
val result = FlywayMigrate.run[IO](jdbc).unsafeRunSync()
assert(result.migrationsExecuted > 0)
}
}

View File

@ -0,0 +1,33 @@
/*
* Copyright 2020 Docspell Contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package docspell.store.migrate
import cats.effect._
import cats.effect.unsafe.implicits._
import docspell.common.LenientUri
import docspell.store.JdbcConfig
import com.dimafeng.testcontainers.MariaDBContainer
import com.dimafeng.testcontainers.munit.TestContainerForAll
import munit._
import org.testcontainers.utility.DockerImageName
class MariaDbMigrateTest extends FunSuite with TestContainerForAll {
override val containerDef: MariaDBContainer.Def =
MariaDBContainer.Def(DockerImageName.parse("mariadb:10.5"))
test("mariadb empty schema migration") {
assume(Docker.existsUnsafe, "docker doesn't exist!")
withContainers { cnt =>
val jdbc =
JdbcConfig(LenientUri.unsafe(cnt.jdbcUrl), cnt.dbUsername, cnt.dbPassword)
val result = FlywayMigrate.run[IO](jdbc).unsafeRunSync()
assert(result.migrationsExecuted > 0)
}
}
}

View File

@ -0,0 +1,33 @@
/*
* Copyright 2020 Docspell Contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package docspell.store.migrate
import cats.effect._
import cats.effect.unsafe.implicits._
import docspell.common.LenientUri
import docspell.store.JdbcConfig
import com.dimafeng.testcontainers.PostgreSQLContainer
import com.dimafeng.testcontainers.munit.TestContainerForAll
import munit._
import org.testcontainers.utility.DockerImageName
class PostgresqlMigrateTest extends FunSuite with TestContainerForAll {
override val containerDef: PostgreSQLContainer.Def =
PostgreSQLContainer.Def(DockerImageName.parse("postgres:13"))
test("postgres empty schema migration") {
assume(Docker.existsUnsafe, "docker doesn't exist!")
withContainers { cnt =>
val jdbc =
JdbcConfig(LenientUri.unsafe(cnt.jdbcUrl), cnt.username, cnt.password)
val result = FlywayMigrate.run[IO](jdbc).unsafeRunSync()
assert(result.migrationsExecuted > 0)
}
}
}

View File

@ -41,10 +41,17 @@ object Dependencies {
val TikaVersion = "2.0.0"
val YamuscaVersion = "0.8.1"
val SwaggerUIVersion = "3.51.2"
val TestContainerVersion = "0.39.6"
val TwelveMonkeysVersion = "3.7.0"
val JQueryVersion = "3.5.1"
val ViewerJSVersion = "0.5.9"
val testContainer = Seq(
"com.dimafeng" %% "testcontainers-scala-munit" % TestContainerVersion,
"com.dimafeng" %% "testcontainers-scala-mariadb" % TestContainerVersion,
"com.dimafeng" %% "testcontainers-scala-postgresql" % TestContainerVersion
)
val catsParse = Seq(
"org.typelevel" %% "cats-parse" % CatsParseVersion
)