Skip to content

Commit

Permalink
Merge pull request #74 from Kusitms-POPTATO-DEV/fix/test-redis-port
Browse files Browse the repository at this point in the history
Fix: test용 redis 포트번호 수정
  • Loading branch information
yeonjookang authored Nov 3, 2024
2 parents a117ee1 + fd6b0cf commit ae180e8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/test/java/server/poptato/auth/api/AuthControllerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package server.poptato.auth.api;

import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.HostConfig;
import com.github.dockerjava.api.model.PortBinding;
import com.github.dockerjava.api.model.Ports;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
Expand All @@ -11,6 +15,8 @@
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
Expand Down Expand Up @@ -53,7 +59,18 @@ public class AuthControllerTest {
private static final GenericContainer<?> redisContainer =
new GenericContainer<>("redis:latest")
.withExposedPorts(6379)
.waitingFor(Wait.forListeningPort());
.waitingFor(Wait.forListeningPort())
.withCreateContainerCmdModifier(cmd ->
cmd.withHostConfig(new HostConfig().withPortBindings(
new PortBinding(Ports.Binding.bindPort(63799), new ExposedPort(6379))
))
);

@DynamicPropertySource
static void configureRedisProperties(DynamicPropertyRegistry registry) {
registry.add("spring.redis.host", redisContainer::getHost);
registry.add("spring.redis.port", () -> redisContainer.getMappedPort(6379));
}

@BeforeEach
void createAccessToken_UserIdIsOne() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package server.poptato.auth.application;

import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.HostConfig;
import com.github.dockerjava.api.model.PortBinding;
import com.github.dockerjava.api.model.Ports;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
Expand Down Expand Up @@ -54,7 +60,18 @@ public class AuthServiceTest {
private static final GenericContainer<?> redisContainer =
new GenericContainer<>("redis:latest")
.withExposedPorts(6379)
.waitingFor(Wait.forListeningPort());
.waitingFor(Wait.forListeningPort())
.withCreateContainerCmdModifier(cmd ->
cmd.withHostConfig(new HostConfig().withPortBindings(
new PortBinding(Ports.Binding.bindPort(63799), new ExposedPort(6379))
))
);

@DynamicPropertySource
static void configureRedisProperties(DynamicPropertyRegistry registry) {
registry.add("spring.redis.host", redisContainer::getHost);
registry.add("spring.redis.port", () -> redisContainer.getMappedPort(6379));
}

@BeforeEach
public void setup() {
Expand Down

0 comments on commit ae180e8

Please sign in to comment.