Add ShadowJar compatibility and Query file can be define name with comment

Add Migration and Query definition class
Add Docker DB for tests
This commit is contained in:
2020-05-10 21:45:50 +02:00
parent df99bf4743
commit 377459f430
19 changed files with 950 additions and 98 deletions

View File

@@ -10,13 +10,12 @@ import org.amshove.kluent.shouldThrow
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import java.io.File
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class MigrationTest() : TestAbstract() {
@Test
fun `run up query`() {
val resources = File(this::class.java.getResource("/sql/migrations").toURI())
val resources = this::class.java.getResource("/sql/migrations").toURI()
val m = Migrations(resources, connection)
m.up().apply {
this `should contain` Pair("1", Migration.Status.OK)
@@ -28,7 +27,7 @@ class MigrationTest() : TestAbstract() {
@Test
fun `migration up Query should throw error if no down`() {
val resources = File(this::class.java.getResource("/sql/migration_without_down").toURI())
val resources = this::class.java.getResource("/sql/migration_without_down").toURI()
invoking {
Migrations(resources, connection)
} shouldThrow Migrations.DownMigrationNotDefined::class
@@ -36,7 +35,7 @@ class MigrationTest() : TestAbstract() {
@Test
fun `run forced down query`() {
val resources = File(this::class.java.getResource("/sql/migrations").toURI())
val resources = this::class.java.getResource("/sql/migrations").toURI()
val m = Migrations(resources, connection)
repeat(3) {
m.down(true).apply {
@@ -48,7 +47,7 @@ class MigrationTest() : TestAbstract() {
@Test
fun `run dry migrations`() {
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
val resources = this::class.java.getResource("/sql/real_migrations").toURI()
Migrations(resources, connection).apply {
runDry().size `should be equal to` 2
}
@@ -59,7 +58,7 @@ class MigrationTest() : TestAbstract() {
@Test
fun `run dry migrations launch twice`() {
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
val resources = this::class.java.getResource("/sql/real_migrations").toURI()
Migrations(resources, connection).apply {
runDry().size `should be equal to` 2
runDry().size `should be equal to` 2
@@ -68,7 +67,7 @@ class MigrationTest() : TestAbstract() {
@Test
fun `run migrations`() {
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
val resources = this::class.java.getResource("/sql/real_migrations").toURI()
Migrations(resources, connection).apply {
run().apply {
size `should be equal to` 1
@@ -78,8 +77,8 @@ class MigrationTest() : TestAbstract() {
@Test
fun `run migrations force down`() {
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
val resourcesFunctions = File(this::class.java.getResource("/sql/function/Test").toURI())
val resources = this::class.java.getResource("/sql/real_migrations").toURI()
val resourcesFunctions = this::class.java.getResource("/sql/function/Test").toURI()
Migrations(listOf(resources, resourcesFunctions), connection).apply {
up().apply {
size `should be equal to` 6
@@ -94,7 +93,7 @@ class MigrationTest() : TestAbstract() {
@Test
fun `run functions migrations`() {
val resources = File(this::class.java.getResource("/sql/function/Test").toURI())
val resources = this::class.java.getResource("/sql/function/Test").toURI()
Migrations(resources, connection).apply {
run().size `should be equal to` 5
}
@@ -110,7 +109,7 @@ class MigrationTest() : TestAbstract() {
@Test
fun `run functions migrations and drop if exist`() {
val resources = File(this::class.java.getResource("/sql/function/Test1").toURI())
val resources = this::class.java.getResource("/sql/function/Test1").toURI()
Migrations(resources, connection).apply {
run().size `should be equal to` 1
}
@@ -123,7 +122,7 @@ class MigrationTest() : TestAbstract() {
Assertions.assertEquals(objTest!!.id, 3)
Assertions.assertEquals(objTest.name, "test")
val resources2 = File(this::class.java.getResource("/sql/function/Test2").toURI())
val resources2 = this::class.java.getResource("/sql/function/Test2").toURI()
Migrations(resources2, connection).apply {
run().size `should be equal to` 1
}