Skip to content

Commit

Permalink
feat(AbstractContainerBaseTest): redis 테스트 컨테이너 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekks committed Nov 13, 2024
1 parent 09ef831 commit a1051b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.sopt.makers.crew.main.external;

import java.util.function.Supplier;

import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;

public abstract class AbstractContainerBaseTest {
static final String REDIS_IMAGE = "redis:6-alpine";
static final GenericContainer REDIS_CONTAINER;

static {
REDIS_CONTAINER = new GenericContainer<>(REDIS_IMAGE)
.withExposedPorts(6379)
.withReuse(true)
.waitingFor(Wait.forListeningPort());
REDIS_CONTAINER.start();
}

@DynamicPropertySource
public static void overrideProps(DynamicPropertyRegistry registry) {
Supplier<Object> getHost = REDIS_CONTAINER::getHost;
registry.add("spring.redis.host", getHost);
registry.add("spring.redis.port", () -> "" + REDIS_CONTAINER.getMappedPort(6379));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.sopt.makers.crew.main.entity.meeting.CoLeaderRepository;
import org.sopt.makers.crew.main.entity.meeting.enums.EnMeetingStatus;
import org.sopt.makers.crew.main.entity.meeting.vo.ImageUrlVO;
import org.sopt.makers.crew.main.external.AbstractContainerBaseTest;
import org.sopt.makers.crew.main.global.annotation.IntegratedTest;
import org.sopt.makers.crew.main.entity.meeting.Meeting;
import org.sopt.makers.crew.main.entity.meeting.MeetingRepository;
Expand Down Expand Up @@ -55,7 +56,7 @@
import org.springframework.test.context.jdbc.SqlGroup;

@IntegratedTest
public class MeetingV2ServiceTest {
public class MeetingV2ServiceTest extends AbstractContainerBaseTest {

@Autowired
private MeetingV2Service meetingV2Service;
Expand Down

0 comments on commit a1051b0

Please sign in to comment.