From 2175653c54a59505e7c51b896343561fc594f42b Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 30 Nov 2023 00:50:18 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=E5=85=A8=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E5=BE=8C=E3=81=ABDB=E3=82=92Drop=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 5 ++--- src/intTest/kotlin/activitypub/inbox/InboxTest.kt | 11 +++++++++++ src/intTest/kotlin/activitypub/note/NoteTest.kt | 11 +++++++++++ .../kotlin/activitypub/webfinger/WebFingerTest.kt | 12 ++++++++++++ .../kotlin/mastodon/account/AccountApiTest.kt | 12 +++++++++++- src/intTest/kotlin/mastodon/apps/AppTest.kt | 11 +++++++++++ src/intTest/kotlin/mastodon/media/MediaTest.kt | 11 +++++++++++ src/intTest/kotlin/mastodon/status/StatusTest.kt | 11 +++++++++++ src/intTest/resources/application.yml | 1 + 9 files changed, 81 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index dfa827dd..a5d52f43 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,6 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.openapitools.generator.gradle.plugin.tasks.GenerateTask -import kotlin.math.max val ktor_version: String by project val kotlin_version: String by project @@ -63,8 +62,8 @@ tasks.check { dependsOn(integrationTest) } tasks.withType { useJUnitPlatform() val cpus = Runtime.getRuntime().availableProcessors() - maxParallelForks = max(1, cpus - 1) - setForkEvery(4) +// maxParallelForks = max(1, cpus - 1) +// setForkEvery(4) doFirst { jvmArgs = arrayOf( "--add-opens", "java.base/java.lang=ALL-UNNAMED" diff --git a/src/intTest/kotlin/activitypub/inbox/InboxTest.kt b/src/intTest/kotlin/activitypub/inbox/InboxTest.kt index 080639b4..a1d2c64f 100644 --- a/src/intTest/kotlin/activitypub/inbox/InboxTest.kt +++ b/src/intTest/kotlin/activitypub/inbox/InboxTest.kt @@ -1,6 +1,8 @@ package activitypub.inbox 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.Test import org.springframework.beans.factory.annotation.Autowired @@ -92,4 +94,13 @@ class InboxTest { @Bean fun testTransaction() = TestTransaction } + + companion object { + @JvmStatic + @AfterAll + fun dropDatabase(@Autowired flyway: Flyway) { + flyway.clean() + flyway.migrate() + } + } } diff --git a/src/intTest/kotlin/activitypub/note/NoteTest.kt b/src/intTest/kotlin/activitypub/note/NoteTest.kt index a559ca66..d2067aa7 100644 --- a/src/intTest/kotlin/activitypub/note/NoteTest.kt +++ b/src/intTest/kotlin/activitypub/note/NoteTest.kt @@ -1,6 +1,8 @@ package activitypub.note 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.Test import org.springframework.beans.factory.annotation.Autowired @@ -178,4 +180,13 @@ class NoteTest { .andExpect { jsonPath("\$.attachment[1].type") { value("Document") } } .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() + } + } } diff --git a/src/intTest/kotlin/activitypub/webfinger/WebFingerTest.kt b/src/intTest/kotlin/activitypub/webfinger/WebFingerTest.kt index d0faaa7f..abee25d6 100644 --- a/src/intTest/kotlin/activitypub/webfinger/WebFingerTest.kt +++ b/src/intTest/kotlin/activitypub/webfinger/WebFingerTest.kt @@ -2,6 +2,8 @@ package activitypub.webfinger import dev.usbharu.hideout.SpringApplication 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.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc @@ -24,6 +26,7 @@ class WebFingerTest { @Test @Sql("/sql/test-user.sql") + fun `webfinger 存在するユーザーを取得`() { mockMvc .get("/.well-known/webfinger?resource=acct:test-user@example.com") @@ -80,4 +83,13 @@ class WebFingerTest { @Bean fun testTransaction(): Transaction = TestTransaction } + + companion object { + @JvmStatic + @AfterAll + fun dropDatabase(@Autowired flyway: Flyway) { + flyway.clean() + flyway.migrate() + } + } } diff --git a/src/intTest/kotlin/mastodon/account/AccountApiTest.kt b/src/intTest/kotlin/mastodon/account/AccountApiTest.kt index 88168a51..b08e2cc5 100644 --- a/src/intTest/kotlin/mastodon/account/AccountApiTest.kt +++ b/src/intTest/kotlin/mastodon/account/AccountApiTest.kt @@ -3,6 +3,8 @@ package mastodon.account import dev.usbharu.hideout.SpringApplication import dev.usbharu.hideout.core.infrastructure.exposedquery.UserQueryServiceImpl 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.Test import org.springframework.beans.factory.annotation.Autowired @@ -37,7 +39,6 @@ class AccountApiTest { private lateinit var mockMvc: MockMvc - @BeforeEach fun setUp() { mockMvc = MockMvcBuilders.webAppContextSetup(context) @@ -133,4 +134,13 @@ class AccountApiTest { } .andExpect { status { isBadRequest() } } } + + companion object { + @JvmStatic + @AfterAll + fun dropDatabase(@Autowired flyway: Flyway) { + flyway.clean() + flyway.migrate() + } + } } diff --git a/src/intTest/kotlin/mastodon/apps/AppTest.kt b/src/intTest/kotlin/mastodon/apps/AppTest.kt index f835d3be..026a9163 100644 --- a/src/intTest/kotlin/mastodon/apps/AppTest.kt +++ b/src/intTest/kotlin/mastodon/apps/AppTest.kt @@ -3,7 +3,9 @@ package mastodon.apps import dev.usbharu.hideout.SpringApplication import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.RegisteredClient import org.assertj.core.api.Assertions.assertThat +import org.flywaydb.core.Flyway import org.jetbrains.exposed.sql.select +import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired @@ -85,4 +87,13 @@ class AppTest { assertThat(app[RegisteredClient.redirectUris]).isEqualTo("https://example.com") assertThat(app[RegisteredClient.scopes]).isEqualTo("read,write") } + + companion object { + @JvmStatic + @AfterAll + fun dropDatabase(@Autowired flyway: Flyway) { + flyway.clean() + flyway.migrate() + } + } } diff --git a/src/intTest/kotlin/mastodon/media/MediaTest.kt b/src/intTest/kotlin/mastodon/media/MediaTest.kt index 898462df..4c9ee710 100644 --- a/src/intTest/kotlin/mastodon/media/MediaTest.kt +++ b/src/intTest/kotlin/mastodon/media/MediaTest.kt @@ -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.SuccessSavedMedia 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.Test import org.mockito.kotlin.any @@ -110,4 +112,13 @@ class MediaTest { .andExpect { status { isForbidden() } } } + companion object { + @JvmStatic + @AfterAll + fun dropDatabase(@Autowired flyway: Flyway) { + flyway.clean() + flyway.migrate() + } + } + } diff --git a/src/intTest/kotlin/mastodon/status/StatusTest.kt b/src/intTest/kotlin/mastodon/status/StatusTest.kt index 2272895a..54b61c9d 100644 --- a/src/intTest/kotlin/mastodon/status/StatusTest.kt +++ b/src/intTest/kotlin/mastodon/status/StatusTest.kt @@ -1,6 +1,8 @@ package mastodon.status 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.Test import org.springframework.beans.factory.annotation.Autowired @@ -142,4 +144,13 @@ class StatusTest { .andExpect { status { isOk() } } .andExpect { jsonPath("\$.in_reply_to_id") { value("1") } } } + + companion object { + @JvmStatic + @AfterAll + fun dropDatabase(@Autowired flyway: Flyway) { + flyway.clean() + flyway.migrate() + } + } } diff --git a/src/intTest/resources/application.yml b/src/intTest/resources/application.yml index 3de298a1..b40fcd91 100644 --- a/src/intTest/resources/application.yml +++ b/src/intTest/resources/application.yml @@ -19,6 +19,7 @@ hideout: spring: flyway: enabled: true + clean-disabled: false datasource: 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;"