From a1051b00c45848f9e950ec1cfd593bcfb35911c3 Mon Sep 17 00:00:00 2001 From: mikekks Date: Wed, 13 Nov 2024 15:02:29 +0900 Subject: [PATCH] =?UTF-8?q?feat(AbstractContainerBaseTest):=20redis=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BB=A8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=84=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../external/AbstractContainerBaseTest.java | 28 +++++++++++++++++++ .../v2/service/MeetingV2ServiceTest.java | 3 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 main/src/test/java/org/sopt/makers/crew/main/external/AbstractContainerBaseTest.java 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;