Skip to content

Commit 8e88156

Browse files
committed
chore: 서버띄워고 테스트 하는 스킬 추가
1 parent 8471da8 commit 8e88156

2 files changed

Lines changed: 99 additions & 0 deletions

File tree

27.9 KB
Binary file not shown.

skills/local-dev-setup.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# 로컬 개발 및 테스트 환경 설정 (H2 & Redis)
2+
3+
## 개요
4+
5+
이 스킬은 `gitanimals` 서버를 로컬에서 H2 데이터베이스와 Redis를 사용하여 실행하고, 테스트 데이터를 채워 넣는 과정을 안내합니다. 이 과정을 통해 실제 DB(MySQL) 없이도 API 동작을 로컬에서 신속하게 검증할 수 있습니다.
6+
7+
## 1단계: 외부 인프라 설정
8+
9+
### 1.1 Redis 실행 (Docker)
10+
11+
서버 실행을 위해 Redis가 필요합니다. Docker가 설치되어 있는지 확인하고 Redis 컨테이너를 실행합니다.
12+
13+
1. **Docker 설치 확인:**
14+
```bash
15+
docker --version
16+
```
17+
*Docker가 없다면 [Docker Desktop](https://www.docker.com/products/docker-desktop/)을 설치하세요.*
18+
19+
2. **Redis 실행:**
20+
```bash
21+
docker run -d -p 6379:6379 --name gitanimals-redis redis
22+
```
23+
24+
### 1.2 H2 데이터베이스 의존성 확인
25+
26+
`build.gradle` 파일에서 H2 의존성이 `implementation` 또는 `runtimeOnly`에 포함되어 있는지 확인합니다. 만약 `testRuntimeOnly`에만 있다면 아래와 같이 추가가 필요할 수 있습니다.
27+
28+
```gradle
29+
// build.gradle (db.gradle 등)
30+
dependencies {
31+
runtimeOnly "com.h2database:h2:${h2Version}"
32+
}
33+
```
34+
35+
## 2단계: 서버 실행
36+
37+
H2를 사용하도록 설정을 오버라이딩하여 서버를 실행합니다.
38+
39+
```bash
40+
./gradlew bootRun --args='--spring.profiles.active=local \
41+
--spring.datasource.url=jdbc:h2:mem:gitanimalsrender;MODE=MySQL;DATABASE_TO_LOWER=TRUE \
42+
--spring.datasource.driver-class-name=org.h2.Driver \
43+
--spring.jpa.hibernate.ddl-auto=create \
44+
--spring.jpa.database-platform=org.hibernate.dialect.H2Dialect'
45+
```
46+
47+
*서버가 실행되면 `localhost:8080/h2-console` (설정된 경우) 등을 통해 접속하거나, 실행 중인 서버에 직접 SQL을 실행할 수 있습니다.*
48+
49+
## 3단계: 테스트 데이터 삽입
50+
51+
서버가 실행 중인 상태에서 (또는 `ddl-auto=create`로 테이블이 생성된 후), 테스트를 위한 유저와 페르소나 데이터를 삽입합니다.
52+
53+
### 3.1 입력 받기
54+
55+
1. **Username 입력:** 추후 API 호출 시 사용할 이름 (예: `my-test-user`)
56+
2. **Pet(Persona) 이름 입력:** `PersonaType` enum 중 하나 (예: `GOOSE`, `CAT`, `SLIME_RED` 등)
57+
58+
### 3.2 SQL 실행 (H2)
59+
60+
H2 콘솔이나 별도의 DB 툴을 통해 아래 쿼리를 실행합니다. (ID는 적절한 Long 값을 사용합니다.)
61+
62+
```sql
63+
-- 1. 유저 생성 (gitanimalsrender.user 테이블)
64+
-- name: 입력받은 username
65+
INSERT INTO user (id, name, visit, last_persona_give_point, version, created_at, modified_at)
66+
VALUES (1, '입력받은_username', 1, 0, 0, NOW(), NOW());
67+
68+
-- 2. 페르소나 생성 (gitanimalsrender.persona 테이블)
69+
-- type: 입력받은 PersonaType
70+
-- user_id: 위에서 생성한 유저의 id (1)
71+
INSERT INTO persona (id, type, level, visible, user_id, version, created_at, modified_at)
72+
VALUES (100, '입력받은_PersonaType', 1, true, 1, 0, NOW(), NOW());
73+
```
74+
75+
## 4단계: API 검증
76+
77+
데이터가 정상적으로 들어갔다면 브라우저나 `curl`을 통해 결과를 확인합니다.
78+
79+
```bash
80+
curl http://localhost:8080/lines/입력받은_username
81+
```
82+
83+
정상적으로 SVG 응답이 온다면 로컬 테스트 환경 설정이 완료된 것입니다.
84+
85+
## PersonaType 목록 참고
86+
87+
주요 PersonaType은 다음과 같습니다:
88+
- `GOOSE`, `GOOSE_SUNGLASSES`
89+
- `LITTLE_CHICK`, `LITTLE_CHICK_SUNGLASSES`
90+
- `PENGUIN`, `PENGUIN_SUNGLASSES`
91+
- `CAT`, `CHEESE_CAT`, `WHITE_CAT`
92+
- `SLIME_RED`, `SLIME_BLUE`, `SLIME_GREEN`
93+
- `PIG`, `PIG_SUNGLASSES`
94+
- `DESSERT_FOX`
95+
- `QUOKKA`
96+
- `MOLE`
97+
- `RABBIT`
98+
99+
*전체 목록은 `src/main/kotlin/org/gitanimals/core/PersonaType.kt`를 참조하세요.*

0 commit comments

Comments
 (0)