Skip to content

Commit

Permalink
feat: 테스트 컨테이너 docker-compose 설정 추가 (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
seokjin8678 authored Jan 3, 2024
1 parent c622cb0 commit 994179c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ val jjwtVersion = "0.12.3"
val mockkVersion = "1.13.4"
val springMockkVersion = "4.0.2"
val testcontainersVersion = "1.19.3"
val testcontainersMysqlVersion = "1.19.3"
val kotestVersion = "5.7.2"
val kotestExtensionTestcontainers = "2.0.2"
val kotestExtensionSpring = "1.1.3"
Expand Down Expand Up @@ -92,7 +91,6 @@ dependencies {

// Testcontainers
testImplementation("org.testcontainers:testcontainers:$testcontainersVersion")
testImplementation("org.testcontainers:mysql:$testcontainersMysqlVersion")

// Kotest
testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion")
Expand Down
11 changes: 4 additions & 7 deletions src/test/kotlin/kr/galaxyhub/sc/GalaxyhubApplicationTests.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package kr.galaxyhub.sc

import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest
import kr.galaxyhub.sc.config.spec.IntegrationSpec

@SpringBootTest
class GalaxyhubApplicationTests {
class GalaxyhubApplicationTests : IntegrationSpec({
describe("contextLoads") {

@Test
fun contextLoads() {
}
}
})
27 changes: 27 additions & 0 deletions src/test/kotlin/kr/galaxyhub/sc/config/spec/IntegrationSpec.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kr.galaxyhub.sc.config.spec

import io.kotest.core.extensions.install
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.extensions.testcontainers.ContainerLifecycleMode
import io.kotest.extensions.testcontainers.DockerComposeContainerExtension
import java.io.File
import org.slf4j.LoggerFactory
import org.springframework.boot.test.context.SpringBootTest
import org.testcontainers.containers.output.Slf4jLogConsumer
import org.testcontainers.containers.wait.strategy.ShellStrategy

@SpringBootTest
abstract class IntegrationSpec(body: DescribeSpec.() -> Unit = {}) : DescribeSpec(body) {

private val log = LoggerFactory.getLogger(javaClass)

init {
install(DockerComposeContainerExtension(File("src/test/resources/docker-compose.yml"), ContainerLifecycleMode.Project))
.apply {
waitingFor("test_mysql", ShellStrategy().withCommand("mysql -u'test' -p'1234' -e'select 1' && sleep 2"))
withLogConsumer("test_mysql", Slf4jLogConsumer(log))
}.apply {
start()
}
}
}
12 changes: 8 additions & 4 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
spring:
datasource:
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
url: jdbc:tc:mysql:8://test_db
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:13306/test
username: test
password: 1234
jpa:
hibernate:
ddl-auto: create
ddl-auto: validate
properties:
hibernate:
format_sql: true
show-sql: true
open-in-view: false
flyway:
enabled: false
enabled: true
baseline-on-migrate: true
baseline-version: 1
logging:
level:
org:
Expand Down
21 changes: 21 additions & 0 deletions src/test/resources/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3.3"
volumes:
mysql_data: { }
services:
test_mysql:
image: mysql:8.0.33
ports:
- "13306:3306"
environment:
TZ: Asia/Seoul
MYSQL_USER: test
MYSQL_PASSWORD: 1234
MYSQL_ROOT_PASSWORD: 1234
MYSQL_DATABASE: test
volumes:
- mysql_data:/var/lib/mysql/
- ./sql:/docker-entrypoint-initdb.d
command:
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_unicode_ci"
- "--skip-character-set-client-handshake"

0 comments on commit 994179c

Please sign in to comment.