Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

테스트 환경 세팅, token 테스트 작성 #118

Merged
merged 10 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 130 additions & 36 deletions .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,136 @@ on:
branches: [ "develop" ]

# 테스트 결과 작성을 위해 쓰기권한 추가
permissions: write-all
permissions:
checks: write
pull-requests: write


# Job 실행
jobs:
build:
runs-on: ubuntu-latest

runs-on: ubuntu-22.04

services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: synergy_db
MYSQL_USER: rivkode
MYSQL_PASSWORD: ${{ secrets.MYSQL_DB_PASSWORD }}
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_DB_PASSWORD }}
ports:
- 3306:3306
redis:
image: redis:latest
ports:
- 6379:6379
mongodb:
image: mongo:4.4.6
env:
MONGO_INITDB_ROOT_USERNAME: rivkode
MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.MONGO_DB_PASSWORD }}
MONGO_INITDB_DATABASE: synergy_db
ports:
- 27017:27017
options: >-
--health-cmd mongo
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: Gradle Caching
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: Grant Execute Permission For Gradlew
run: chmod +x gradlew

- name: Build With Gradle
run: ./gradlew build -x test

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: ${{ always() }}
with:
files: build/test-results/**/*.xml

- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/build/test-results/test/TEST-*.xml'

- name: 레포지토리 체크아웃
uses: actions/checkout@v4

# - name: 기본 MySQL 종료 (SUDO 필요)
# run: sudo service mysql stop # 기본 MySQL 종료

- name: JDK 17 설치
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: Gradle Caching
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: MySQL 설치
# uses: mirromutth/mysql-action@v1
# with:
# mysql version: '8.0' # Optional, default value is "latest". The version of the MySQL
# mysql database: synergy_db # Optional, default value is "test". The specified database which will be create
# mysql user: rivkode # Required if "mysql root password" is empty, default is empty. The superuser for the specified database. Of course you can use secrets, too
# mysql password: ${{ secrets.MYSQL_DB_PASSWORD }}

- name: Wait for MySQL
run: |
while ! mysqladmin ping --host=127.0.0.1 --password=$DB_PASSWORD --silent; do
sleep 1
done

- name: Install mongosh
run: |
sudo apt-get install gnupg
wget -qO- https://www.mongodb.org/static/pgp/server-7.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-7.0.asc
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt-get update
sudo apt-get install -y mongodb-mongosh
mongosh --version

- name: Initalize MongoDB
run: |
mongosh --host localhost:27017 -u rivkode -p ${{ secrets.MONGO_DB_PASSWORD }} --authenticationDatabase admin <<EOF
db = db.getSiblingDB('APP-DB');
db.createUser({ user: 'rivkode', pwd: ${{ secrets.MONGO_DB_PASSWORD }} , roles: [{ role: 'readWrite', db: 'APP-DB' }] })
db.createCollection('APP-COLLECTION');
EOF
# Do whatever you like in here

- name: properties 파일 생성
run: |
cd ./src/main
mkdir resources
cd ./resources
touch ./application.properties
echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./application.properties

- name: Verify application.properties
run: cat ./src/main/resources/application.properties
shell: bash

- name: Verify MySQL is running
run: sudo netstat -tlnp | grep 3306

# gradle 실행 허가
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew

- name: 빌드 진행
run: ./gradlew build -x test

- name: 테스트 코드 실행
run: ./gradlew --info test

- name: 테스트 결과 PR에 코멘트 작성
uses: EnricoMi/publish-unit-test-result-action@v2
if: always() # 테스트가 실패했을때만 or 테스트가 성공했을때만 알려주기(여기선 둘다!)
with:
files: |
**/build/test-results/**/*.xml

# Files changed에서 어디에서 잘못되었는지 가르쳐준다.
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/build/test-results/test/TEST-*.xml'
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
public class TokenGeneratorUUIDTest {
class TokenGeneratorUUIDTest {
@Autowired
IdGenerator idGenerator;

@Autowired
TokenGenerator tokenGenerator;

@DisplayName("객체 ID 1만개 생성시 1초 이내로 실행된다.")
@Test
void generateLongId() {
List<Long> longList = new ArrayList<>();
Expand All @@ -27,18 +28,18 @@ void generateLongId() {

for (int i = 0; i < 10000; i++) {
Long longId = idGenerator.generateId();
System.out.println("longId : " + i + " 번째 : "+ longId);
longList.add(longId);

}

// test end
long endTime = System.currentTimeMillis();
System.out.println("longId Total execution time: " + (endTime - startTime) + " milliseconds");
long elapsedTime = endTime - startTime;

assertThat(longList.size()).isEqualTo(10000);
// test end
assertThat(longList).hasSize(10000);
assertThat(elapsedTime).isLessThanOrEqualTo(1000);
}

@DisplayName("대체키 ID 1만개 생성시 3초 이내로 실행된다.")
@Test
void generateStringId() {
List<String> stringList = new ArrayList<>();
Expand All @@ -48,16 +49,14 @@ void generateStringId() {

for (int i = 0; i < 10000; i++) {
String stringId = tokenGenerator.generateToken(IdPrefix.POST);
System.out.println("stringId : " + i + " 번째 : "+ stringId);
stringList.add(stringId);
}

// test end
long endTime = System.currentTimeMillis();
System.out.println("stringId Total execution time: " + (endTime - startTime) + " milliseconds");
long elapsedTime = endTime - startTime;

assertThat(stringList.size()).isEqualTo(10000);
assertThat(stringList).hasSize(10000);
assertThat(elapsedTime).isLessThanOrEqualTo(3000);
}


}

This file was deleted.

Loading
Loading