feature #2: save executed migration in DB

This commit is contained in:
2019-07-05 10:04:14 +02:00
parent 6cc3152215
commit 9c02fd21ca
12 changed files with 147 additions and 65 deletions

View File

@@ -16,8 +16,12 @@ class MigrationTest(): TestAbstract() {
fun upQuery() {
val resources = File(this::class.java.getResource("/sql/migrations").toURI())
val m = Migrations(resources, getConnextion())
m.up() `should contain` Pair("1", Migration.Status.OK)
m.up().size `should be equal to` 1
m.up().let {
it `should contain` Pair("1", Migration.Status.OK)
it.size `should be equal to` 1
}
m.up().size `should be equal to` 0
}
@Test
@@ -32,15 +36,22 @@ class MigrationTest(): TestAbstract() {
fun downQuery() {
val resources = File(this::class.java.getResource("/sql/migrations").toURI())
val m = Migrations(resources, getConnextion())
m.down() `should contain` Pair("1", Migration.Status.OK)
m.down().size `should be equal to` 1
repeat(3) {
m.down(true).let {
it `should contain` Pair("1", Migration.Status.OK)
it.size `should be equal to` 1
}
}
}
@Test
fun `test up and down migrations`() {
val resources = File(this::class.java.getResource("/sql/real_migrations").toURI())
val m = Migrations(resources, getConnextion())
m.test().size `should be equal to` 2
m.test().size `should be equal to` 2
Migrations(resources, getConnextion()).apply {
test().size `should be equal to` 2
}
Migrations(resources, getConnextion()).apply {
test().size `should be equal to` 2
}
}
}

View File

@@ -1,8 +1,8 @@
package fr.postgresjson
import fr.postgresjson.connexion.Connection
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
import java.io.File
@@ -13,14 +13,14 @@ abstract class TestAbstract {
return Connection(database = "test", username = "test", password = "test")
}
@BeforeAll
@BeforeEach
fun beforeAll() {
val initSQL = File(this::class.java.getResource("/fixtures/init.sql").toURI())
val promise = getConnextion().connect().sendQuery(initSQL.readText())
promise.join()
}
@AfterAll
@AfterEach
fun afterAll() {
val downSQL = File(this::class.java.getResource("/fixtures/down.sql").toURI())
getConnextion().connect().sendQuery(downSQL.readText()).join()