Skip to content

Commit

Permalink
chore: 테스트 컨테이너 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mirageoasis committed Aug 21, 2024
1 parent 6ff336f commit 075f15a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.junit.jupiter.Testcontainers;

@Testcontainers
Expand All @@ -12,14 +13,36 @@ public class TestContainerStarter {
private static final int REDIS_PORT = 6379;
private static final GenericContainer<?> REDIS;

private static final String MYSQL_IMAGE = "mysql:8.0.32";
private static final int MYSQL_PORT = 3306;
private static final MySQLContainer<?> MYSQL;

static {
REDIS = new GenericContainer<>(REDIS_IMAGE).withExposedPorts(REDIS_PORT).withReuse(true);
REDIS.start();

MYSQL =
new MySQLContainer<>(MYSQL_IMAGE)
.withExposedPorts(MYSQL_PORT)
.withUsername("root")
.withPassword("root")
.withDatabaseName("ticketing")
.withReuse(false);
MYSQL.start();
}

@DynamicPropertySource
private static void registerRedisProperties(DynamicPropertyRegistry registry) {
private static void registerProperties(DynamicPropertyRegistry registry) {
registry.add("spring.data.redis.host", REDIS::getHost);
registry.add("spring.data.redis.port", () -> REDIS.getMappedPort(REDIS_PORT).toString());

String mysqlUrl =
String.format(
"jdbc:mysql://%s:%s/ticketing",
MYSQL.getHost(), MYSQL.getMappedPort(MYSQL_PORT));

registry.add("spring.datasource.url", () -> mysqlUrl);
registry.add("spring.datasource.username", () -> "root");
registry.add("spring.datasource.password", () -> "root");
}
}
18 changes: 18 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
spring:
data:
redis:
host: localhost
port: 6379
datasource:
url: jdbc:mysql://localhost:3306/ticketing
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: create-drop

jwt:
issuer: test
expiry-seconds: 1800
secret: thisisjusttestaccesssecretsodontworry

0 comments on commit 075f15a

Please sign in to comment.