test: 全テスト後にDBをDropするように

This commit is contained in:
usbharu 2023-11-30 00:50:18 +09:00
parent 2d5f547f13
commit 2175653c54
9 changed files with 81 additions and 4 deletions

View File

@ -2,7 +2,6 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
import kotlin.math.max
val ktor_version: String by project val ktor_version: String by project
val kotlin_version: String by project val kotlin_version: String by project
@ -63,8 +62,8 @@ tasks.check { dependsOn(integrationTest) }
tasks.withType<Test> { tasks.withType<Test> {
useJUnitPlatform() useJUnitPlatform()
val cpus = Runtime.getRuntime().availableProcessors() val cpus = Runtime.getRuntime().availableProcessors()
maxParallelForks = max(1, cpus - 1) // maxParallelForks = max(1, cpus - 1)
setForkEvery(4) // setForkEvery(4)
doFirst { doFirst {
jvmArgs = arrayOf( jvmArgs = arrayOf(
"--add-opens", "java.base/java.lang=ALL-UNNAMED" "--add-opens", "java.base/java.lang=ALL-UNNAMED"

View File

@ -1,6 +1,8 @@
package activitypub.inbox package activitypub.inbox
import dev.usbharu.hideout.SpringApplication import dev.usbharu.hideout.SpringApplication
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
@ -92,4 +94,13 @@ class InboxTest {
@Bean @Bean
fun testTransaction() = TestTransaction fun testTransaction() = TestTransaction
} }
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
flyway.clean()
flyway.migrate()
}
}
} }

View File

@ -1,6 +1,8 @@
package activitypub.note package activitypub.note
import dev.usbharu.hideout.SpringApplication import dev.usbharu.hideout.SpringApplication
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
@ -178,4 +180,13 @@ class NoteTest {
.andExpect { jsonPath("\$.attachment[1].type") { value("Document") } } .andExpect { jsonPath("\$.attachment[1].type") { value("Document") } }
.andExpect { jsonPath("\$.attachment[1].url") { value("https://example.com/media/test-media2.png") } } .andExpect { jsonPath("\$.attachment[1].url") { value("https://example.com/media/test-media2.png") } }
} }
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
flyway.clean()
flyway.migrate()
}
}
} }

View File

@ -2,6 +2,8 @@ package activitypub.webfinger
import dev.usbharu.hideout.SpringApplication import dev.usbharu.hideout.SpringApplication
import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.application.external.Transaction
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
@ -24,6 +26,7 @@ class WebFingerTest {
@Test @Test
@Sql("/sql/test-user.sql") @Sql("/sql/test-user.sql")
fun `webfinger 存在するユーザーを取得`() { fun `webfinger 存在するユーザーを取得`() {
mockMvc mockMvc
.get("/.well-known/webfinger?resource=acct:test-user@example.com") .get("/.well-known/webfinger?resource=acct:test-user@example.com")
@ -80,4 +83,13 @@ class WebFingerTest {
@Bean @Bean
fun testTransaction(): Transaction = TestTransaction fun testTransaction(): Transaction = TestTransaction
} }
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
flyway.clean()
flyway.migrate()
}
}
} }

View File

@ -3,6 +3,8 @@ package mastodon.account
import dev.usbharu.hideout.SpringApplication import dev.usbharu.hideout.SpringApplication
import dev.usbharu.hideout.core.infrastructure.exposedquery.UserQueryServiceImpl import dev.usbharu.hideout.core.infrastructure.exposedquery.UserQueryServiceImpl
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
@ -37,7 +39,6 @@ class AccountApiTest {
private lateinit var mockMvc: MockMvc private lateinit var mockMvc: MockMvc
@BeforeEach @BeforeEach
fun setUp() { fun setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(context) mockMvc = MockMvcBuilders.webAppContextSetup(context)
@ -133,4 +134,13 @@ class AccountApiTest {
} }
.andExpect { status { isBadRequest() } } .andExpect { status { isBadRequest() } }
} }
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
flyway.clean()
flyway.migrate()
}
}
} }

View File

@ -3,7 +3,9 @@ package mastodon.apps
import dev.usbharu.hideout.SpringApplication import dev.usbharu.hideout.SpringApplication
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.RegisteredClient import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.RegisteredClient
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.flywaydb.core.Flyway
import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.select
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
@ -85,4 +87,13 @@ class AppTest {
assertThat(app[RegisteredClient.redirectUris]).isEqualTo("https://example.com") assertThat(app[RegisteredClient.redirectUris]).isEqualTo("https://example.com")
assertThat(app[RegisteredClient.scopes]).isEqualTo("read,write") assertThat(app[RegisteredClient.scopes]).isEqualTo("read,write")
} }
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
flyway.clean()
flyway.migrate()
}
}
} }

View File

@ -5,6 +5,8 @@ import dev.usbharu.hideout.core.service.media.MediaDataStore
import dev.usbharu.hideout.core.service.media.MediaSaveRequest import dev.usbharu.hideout.core.service.media.MediaSaveRequest
import dev.usbharu.hideout.core.service.media.SuccessSavedMedia import dev.usbharu.hideout.core.service.media.SuccessSavedMedia
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.kotlin.any import org.mockito.kotlin.any
@ -110,4 +112,13 @@ class MediaTest {
.andExpect { status { isForbidden() } } .andExpect { status { isForbidden() } }
} }
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
flyway.clean()
flyway.migrate()
}
}
} }

View File

@ -1,6 +1,8 @@
package mastodon.status package mastodon.status
import dev.usbharu.hideout.SpringApplication import dev.usbharu.hideout.SpringApplication
import org.flywaydb.core.Flyway
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
@ -142,4 +144,13 @@ class StatusTest {
.andExpect { status { isOk() } } .andExpect { status { isOk() } }
.andExpect { jsonPath("\$.in_reply_to_id") { value("1") } } .andExpect { jsonPath("\$.in_reply_to_id") { value("1") } }
} }
companion object {
@JvmStatic
@AfterAll
fun dropDatabase(@Autowired flyway: Flyway) {
flyway.clean()
flyway.migrate()
}
}
} }

View File

@ -19,6 +19,7 @@ hideout:
spring: spring:
flyway: flyway:
enabled: true enabled: true
clean-disabled: false
datasource: datasource:
driver-class-name: org.h2.Driver driver-class-name: org.h2.Driver
url: "jdbc:h2:mem:test;MODE=POSTGRESQL;DB_CLOSE_DELAY=-1;CASE_INSENSITIVE_IDENTIFIERS=true;TRACE_LEVEL_FILE=4;" url: "jdbc:h2:mem:test;MODE=POSTGRESQL;DB_CLOSE_DELAY=-1;CASE_INSENSITIVE_IDENTIFIERS=true;TRACE_LEVEL_FILE=4;"