Skip to content

Commit

Permalink
[Refactor/#209] 테스트 컨테이너 및 액션 개선 (#327)
Browse files Browse the repository at this point in the history
* refactor: docker 설정 분리

* refactor: 모듈별 테스트를 위한 컨테이너 반복 생성 하지 않도록 수정

* refactor: 테스트 병렬 실행 옵션 추가

* chore: action 로그 레벨 조정

* refactor: action에서 모듈별 테스트 분리

* refactor: jooqCodegen 테스크 수정

* refactor: jooqCodegen 캐싱할 수 있도록 수정

* refactor: 액션 분리로 인한 -parallel 옵션 제거

* refactor: 테스크 의존성 수정

* chore: validate-test 액션 정리

* fix: Cache Jooq 사용 수정

* refactor: api-repo, batch cache jooq 분리

* refactor: 공통 의존성을 제외한 주입 의존성 각각의 컨트롤러에서 주입되도록 수정
  • Loading branch information
belljun3395 authored Aug 8, 2024
1 parent 7733a7c commit 7e1c21a
Show file tree
Hide file tree
Showing 24 changed files with 283 additions and 228 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/code-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ jobs:

- name: Jooq Code Generation
run: |
./gradlew --info jooqCodegenAll
./gradlew jooqCodegenAll
- name: Test with Gradle
run: |
./gradlew --info test
./gradlew test -parallel
- name: Build with Gradle
run: |
./gradlew --info api:build -x test
./gradlew api:build -x test
- name: Generate OpenAPI3
run: |
./gradlew --info api:openapi3 -PserverUrl=https://api.fewletter.site
./gradlew api:openapi3 -PserverUrl=https://api.fewletter.site
- name: Generate Swagger
run: |
./gradlew --info api:generateStaticSwaggerUIApi
./gradlew api:generateStaticSwaggerUIApi
- name : Docker Login
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}

- name: Build Docker Image
run: |
./gradlew --info api:buildDockerImage -PimageName=fewletter/api -PreleaseVersion=${{ env.RELEASE_VERSION }}
./gradlew api:buildDockerImage -PimageName=fewletter/api -PreleaseVersion=${{ env.RELEASE_VERSION }}
6 changes: 3 additions & 3 deletions .github/workflows/ecs-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ jobs:
- name: Test with Gradle
run: |
./gradlew test
./gradlew test -parallel
- name: Generate OpenAPI3
run: |
./gradlew --info api:openapi3 -PserverUrl=https://api.fewletter.site
./gradlew api:openapi3 -PserverUrl=https://api.fewletter.site
- name: Generate Swagger
run: |
./gradlew --info api:generateStaticSwaggerUIApi
./gradlew api:generateStaticSwaggerUIApi
- name: Build with Gradle bootBuildImage, tag, and push image to Amazon ECR
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ecs-dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ jobs:
- name: Test with Gradle
run: |
./gradlew test
./gradlew test -parallel
- name: Generate OpenAPI3
run: |
./gradlew --info api:openapi3 -PserverUrl=https://api.fewletter.shop
./gradlew api:openapi3 -PserverUrl=https://api.fewletter.shop
- name: Generate Swagger
run: |
./gradlew --info api:generateStaticSwaggerUIApi
./gradlew api:generateStaticSwaggerUIApi
- name: Build with Gradle bootBuildImage, tag, and push image to Amazon ECR
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
run: chmod +x gradlew

- name: Test with Ktlint
run: ./gradlew --info ktlintCheck
run: ./gradlew ktlintCheck
4 changes: 2 additions & 2 deletions .github/workflows/sql-explain-hook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ jobs:
- name: Jooq Code Generation
run: |
./gradlew --info jooqCodegenAll
./gradlew jooqCodegenAll
- name: Generate Explain Docs
run: |
./gradlew --info api-repo:generateExplainDocs
./gradlew api-repo:generateExplainDocs
- name: Zip Explain Docs
run: |
Expand Down
139 changes: 135 additions & 4 deletions .github/workflows/validate-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}

jobs:
validate-test:
setup-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -34,8 +34,139 @@ jobs:
- name: Jooq Code Generation
run: |
./gradlew --info jooqCodegenAll
./gradlew jooqCodegenAll
- name: Test with Gradle
- name: Cache Api Repo Jooq
uses: actions/cache@v3
with:
path: |
./api-repo/src/generated
./api-repo/src/main/resources/db/migration
key: ${{ runner.os }}-api-repo-jooq-${{ hashFiles('./api-repo/src/generated/**', './api-repo/src/main/resources/db/migration/**') }}
restore-keys: |
${{ runner.os }}-api-repo-jooq-
- name: Cache Batch Jooq
uses: actions/cache@v3
with:
path: |
./batch/src/generated
./batch/src/main/resources/db/migration
key: ${{ runner.os }}-batch-jooq-${{ hashFiles('./batch/src/generated/**', './batch/src/main/resources/db/migration/**') }}
restore-keys: |
${{ runner.os }}-batch-jooq-
api-test:
needs: setup-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Cache Gradle
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache Api Repo Jooq
uses: actions/cache@v3
with:
path: |
./api-repo/src/generated
./api-repo/src/main/resources/db/migration
key: ${{ runner.os }}-api-repo-jooq-${{ hashFiles('./api-repo/src/generated/**', './api-repo/src/main/resources/db/migration/**') }}
restore-keys: |
${{ runner.os }}-api-repo-jooq-
- name: Cache Batch Jooq
uses: actions/cache@v3
with:
path: |
./batch/src/generated
./batch/src/main/resources/db/migration
key: ${{ runner.os }}-batch-jooq-${{ hashFiles('./batch/src/generated/**', './batch/src/main/resources/db/migration/**') }}
restore-keys: |
${{ runner.os }}-batch-jooq-
- name: API Test with Gradle
run: |
./gradlew --info test
./gradlew api:test
api-repo-test:
needs: setup-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Cache Gradle
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-jooq-${{ hashFiles('./api-repo/src/generated/**', './api-repo/src/main/resources/db/migration/**', './batch/src/generated/**', './batch/src/main/resources/db/migration/**') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache Api Repo Jooq
uses: actions/cache@v3
with:
path: |
./api-repo/src/generated
./api-repo/src/main/resources/db/migration
key: ${{ runner.os }}-api-repo-jooq-${{ hashFiles('./api-repo/src/generated/**', './api-repo/src/main/resources/db/migration/**') }}
restore-keys: |
${{ runner.os }}-api-repo-jooq-
- name: API Repo Test with Gradle
run: |
./gradlew api-repo:test
batch-test:
needs: setup-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Cache Gradle
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache Batch Jooq
uses: actions/cache@v3
with:
path: |
./batch/src/generated
./batch/src/main/resources/db/migration
key: ${{ runner.os }}-batch-jooq-${{ hashFiles('./batch/src/generated/**', './batch/src/main/resources/db/migration/**') }}
restore-keys: |
${{ runner.os }}-batch-jooq-
- name: Batch Test with Gradle
run: |
./gradlew batch:test
2 changes: 1 addition & 1 deletion api-repo/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ logging:
spring:
datasource:
hikari:
jdbcUrl: jdbc:mysql://localhost:13306/api?allowPublicKeyRetrieval=true&rewriteBatchedStatements=true&allowMultiQueries=true
jdbcUrl: jdbc:mysql://localhost:33306/api?allowPublicKeyRetrieval=true&rewriteBatchedStatements=true&allowMultiQueries=true
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
Expand Down
2 changes: 1 addition & 1 deletion api-repo/src/test/resources/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ services:
- TZ=Asia/Seoul
command: [ "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci", "--lower_case_table_names=1", "--max_connections=2048", "--wait_timeout=3600" ]
ports:
- "13306:3306"
- "33306:3306"
volumes:
- ./mysql-init.d:/docker-entrypoint-initdb.d
101 changes: 101 additions & 0 deletions api/src/test/kotlin/com/few/api/web/controller/ControllerTestSpec.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
package com.few.api.web.controller

import com.fasterxml.jackson.databind.ObjectMapper
import com.few.api.ApiMain
import com.few.api.domain.admin.document.usecase.*
import com.few.api.domain.article.usecase.ReadArticleUseCase
import com.few.api.domain.article.usecase.ReadArticlesUseCase
import com.few.api.domain.log.AddApiLogUseCase
import com.few.api.domain.member.usecase.SaveMemberUseCase
import com.few.api.domain.member.usecase.TokenUseCase
import com.few.api.domain.problem.usecase.BrowseProblemsUseCase
import com.few.api.domain.problem.usecase.CheckProblemUseCase
import com.few.api.domain.problem.usecase.ReadProblemUseCase
import com.few.api.domain.subscription.usecase.BrowseSubscribeWorkbooksUseCase
import com.few.api.domain.subscription.usecase.SubscribeWorkbookUseCase
import com.few.api.domain.subscription.usecase.UnsubscribeAllUseCase
import com.few.api.domain.subscription.usecase.UnsubscribeWorkbookUseCase
import com.few.api.domain.workbook.article.usecase.ReadWorkBookArticleUseCase
import com.few.api.domain.workbook.usecase.BrowseWorkbooksUseCase
import com.few.api.domain.workbook.usecase.ReadWorkbookUseCase
import com.few.api.security.token.TokenResolver
import com.few.api.web.handler.ApiControllerExceptionHandler
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.restdocs.RestDocumentationExtension
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.test.web.servlet.MockMvc

@ActiveProfiles(value = ["test", "new"])
@AutoConfigureRestDocs
Expand All @@ -19,6 +40,86 @@ import org.springframework.test.context.ContextConfiguration
@ContextConfiguration(initializers = [ControllerTestContainerInitializer::class])
abstract class ControllerTestSpec {

/** Common */
@Autowired
lateinit var apiControllerExceptionHandler: ApiControllerExceptionHandler

@Autowired
lateinit var objectMapper: ObjectMapper

lateinit var webTestClient: WebTestClient

@Autowired
lateinit var mockMvc: MockMvc

@MockBean
lateinit var tokenResolver: TokenResolver

/** AdminControllerTest */
@MockBean
lateinit var addArticleUseCase: AddArticleUseCase

@MockBean
lateinit var addWorkbookUseCase: AddWorkbookUseCase

@MockBean
lateinit var mapArticleUseCase: MapArticleUseCase

@MockBean
lateinit var convertContentUseCase: ConvertContentUseCase

@MockBean
lateinit var putImageUseCase: PutImageUseCase

/** ApiLogControllerTest */
@MockBean
lateinit var addApiLogUseCase: AddApiLogUseCase

/** ArticleControllerTest */
@MockBean
lateinit var readArticleUseCase: ReadArticleUseCase

@MockBean
lateinit var readArticlesUseCase: ReadArticlesUseCase

/** MemberControllerTest */
@MockBean
lateinit var saveMemberUseCase: SaveMemberUseCase

@MockBean
lateinit var tokenUseCase: TokenUseCase

/** ProblemControllerTest */
@MockBean
lateinit var browseProblemsUseCase: BrowseProblemsUseCase

@MockBean
lateinit var readProblemUseCase: ReadProblemUseCase

@MockBean
lateinit var checkProblemUseCase: CheckProblemUseCase

/** SubscriptionControllerTest */
@MockBean
lateinit var subscribeWorkbookUseCase: SubscribeWorkbookUseCase

@MockBean
lateinit var unsubscribeWorkbookUseCase: UnsubscribeWorkbookUseCase

@MockBean
lateinit var unsubscribeAllUseCase: UnsubscribeAllUseCase

@MockBean
lateinit var browseSubscribeWorkbooksUseCase: BrowseSubscribeWorkbooksUseCase

/** WorkBookArticleControllerTest */
@MockBean
lateinit var readWorkBookArticleUseCase: ReadWorkBookArticleUseCase

/** WorkBookControllerTest */
@MockBean
lateinit var readWorkbookUseCase: ReadWorkbookUseCase

@MockBean
lateinit var browseWorkBooksUseCase: BrowseWorkbooksUseCase
}
Loading

0 comments on commit 7e1c21a

Please sign in to comment.