diff --git a/.github/workflows/develop_build_deploy.yml b/.github/workflows/develop_build_deploy.yml index 2806e0d..7d8d7d9 100644 --- a/.github/workflows/develop_build_deploy.yml +++ b/.github/workflows/develop_build_deploy.yml @@ -25,6 +25,16 @@ jobs: java-version: '17' distribution: 'temurin' + # 테스트 환경에서 필요한 컨테이너 실행 (redis, postgres) + - name: Run Containers + run: docker compose -f ./docker-compose-test.yml up -d + + # 테스트 환경에서 필요한 스키마, 데이터 등록 + - name: Apply Schema and Data + run: | + echo "${{ secrets.SCHEMA_SQL }}" > src/test/resources/test-schema.sql + echo "${{ secrets.DATA_SQL }}" > src/test/resources/test-data.sql + # Gradlew 실행 권한 허용 - name: Grant Execute Permission for Gradlew run: chmod +x ./gradlew diff --git a/.github/workflows/develop_pull_request.yml b/.github/workflows/develop_pull_request.yml index 3085223..aebb5cd 100644 --- a/.github/workflows/develop_pull_request.yml +++ b/.github/workflows/develop_pull_request.yml @@ -20,6 +20,16 @@ jobs: java-version: '17' distribution: 'temurin' + # 테스트 환경에서 필요한 컨테이너 실행 (redis, postgres) + - name: Run Containers + run: docker compose -f ./docker-compose-test.yml up -d + + # 테스트 환경에서 필요한 스키마, 데이터 등록 + - name: Apply Schema and Data + run: | + echo "${{ secrets.SCHEMA_SQL }}" > src/test/resources/test-schema.sql + echo "${{ secrets.DATA_SQL }}" > src/test/resources/test-data.sql + # Gradlew 실행 권한 허용 - name: Grant Execute Permission for Gradlew run: chmod +x ./gradlew diff --git a/.gitignore b/.gitignore index ca66177..5f9f806 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,7 @@ out/ .vscode/ ### env ### -.env \ No newline at end of file +.env + +### sql ### +*.sql \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7bdb570..2c5d574 100644 --- a/build.gradle +++ b/build.gradle @@ -36,13 +36,11 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-mail' - runtimeOnly 'com.h2database:h2' runtimeOnly 'org.postgresql:postgresql' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'io.hypersistence:hypersistence-utils-hibernate-63:3.9.3' - // Validation implementation 'org.springframework.boot:spring-boot-starter-validation' diff --git a/docker-compose-test.yml b/docker-compose-test.yml new file mode 100644 index 0000000..7d58b49 --- /dev/null +++ b/docker-compose-test.yml @@ -0,0 +1,14 @@ +services: + redis: + image: "redis:alpine" + ports: + - "6379:6379" + + postgres: + image: "postgres:alpine" + ports: + - "5432:5432" + environment: + POSTGRES_USER: test + POSTGRES_PASSWORD: test + POSTGRES_DB: "ftm_test_db" # DB 자동 생성 \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index e5d5a77..b0c786a 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -37,7 +37,7 @@ - + diff --git a/src/test/java/com/ftm/server/ServerApplicationTests.java b/src/test/java/com/ftm/server/ServerApplicationTests.java index 5b67a07..325a20e 100644 --- a/src/test/java/com/ftm/server/ServerApplicationTests.java +++ b/src/test/java/com/ftm/server/ServerApplicationTests.java @@ -1,11 +1,16 @@ package com.ftm.server; import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestPropertySource; @SpringBootTest +@ActiveProfiles("test") @TestPropertySource(locations = "file:.env") +@AutoConfigureTestDatabase( + replace = AutoConfigureTestDatabase.Replace.NONE) // 테스트 시 내장된 인메모리 DB를 사용하지 않는다는 설정 class ServerApplicationTests { @Test diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index 2f35b9c..5adcf85 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -4,14 +4,24 @@ spring: on-profile: "test" datasource: - url: jdbc:h2:mem:testDb;MODE=POSTGRESQL + url: jdbc:postgresql://localhost:5432/ftm_test_db + username: test + password: test + driver-class-name: org.postgresql.Driver jpa: - database-platform: org.hibernate.dialect.H2Dialect + database-platform: org.hibernate.dialect.PostgreSQLDialect hibernate: ddl-auto: none show-sql: true properties : hibernate: format_sql: true - default_batch_fetch_size: 1000 \ No newline at end of file + default_batch_fetch_size: 1000 + + sql: + init: + mode: always + schema-locations: classpath:test-schema.sql + data-locations: classpath:test-data.sql +