diff --git a/main/src/test/java/org/sopt/makers/crew/main/external/AbstractContainerBaseTest.java b/main/src/test/java/org/sopt/makers/crew/main/external/AbstractContainerBaseTest.java new file mode 100644 index 00000000..f2b2be99 --- /dev/null +++ b/main/src/test/java/org/sopt/makers/crew/main/external/AbstractContainerBaseTest.java @@ -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 getHost = REDIS_CONTAINER::getHost; + registry.add("spring.redis.host", getHost); + registry.add("spring.redis.port", () -> "" + REDIS_CONTAINER.getMappedPort(6379)); + } +} \ No newline at end of file diff --git a/main/src/test/java/org/sopt/makers/crew/main/meeting/v2/service/MeetingV2ServiceTest.java b/main/src/test/java/org/sopt/makers/crew/main/meeting/v2/service/MeetingV2ServiceTest.java index 7ee97255..1f12b156 100644 --- a/main/src/test/java/org/sopt/makers/crew/main/meeting/v2/service/MeetingV2ServiceTest.java +++ b/main/src/test/java/org/sopt/makers/crew/main/meeting/v2/service/MeetingV2ServiceTest.java @@ -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; @@ -55,7 +56,7 @@ import org.springframework.test.context.jdbc.SqlGroup; @IntegratedTest -public class MeetingV2ServiceTest { +public class MeetingV2ServiceTest extends AbstractContainerBaseTest { @Autowired private MeetingV2Service meetingV2Service;