From 4af803eae430e7120501fb501eb4b3ac30f12f85 Mon Sep 17 00:00:00 2001 From: govl6113 Date: Mon, 6 Nov 2023 19:50:25 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20redis=20test=20container=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 +-- .../server/config/RedisTestContainers.java | 26 +++++++++++++++++++ src/test/resources/docker-compose.yml | 8 ++++++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/test/java/prography/cakeke/server/config/RedisTestContainers.java create mode 100644 src/test/resources/docker-compose.yml diff --git a/build.gradle b/build.gradle index 09e79da..391208d 100644 --- a/build.gradle +++ b/build.gradle @@ -26,9 +26,6 @@ dependencies { runtimeOnly 'com.h2database:h2' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' - implementation('it.ozimov:embedded-redis:0.7.3') { - exclude group: 'org.slf4j', module: 'slf4j-simple' - } // sql implementation group: 'org.postgresql', name: 'postgresql', version: '42.3.1' @@ -41,6 +38,7 @@ dependencies { // test testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.testcontainers:testcontainers:1.17.2' // Swagger implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.4' diff --git a/src/test/java/prography/cakeke/server/config/RedisTestContainers.java b/src/test/java/prography/cakeke/server/config/RedisTestContainers.java new file mode 100644 index 0000000..5292888 --- /dev/null +++ b/src/test/java/prography/cakeke/server/config/RedisTestContainers.java @@ -0,0 +1,26 @@ +package prography.cakeke.server.config; + +import org.junit.jupiter.api.DisplayName; +import org.springframework.context.annotation.Configuration; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.utility.DockerImageName; + +@DisplayName("Redis Test Containers") +@Configuration +public class RedisTestContainers { + + private static final String REDIS_DOCKER_IMAGE = "redis:5.0.3-alpine"; + + static { // (1) + GenericContainer REDIS_CONTAINER = + new GenericContainer<>(DockerImageName.parse(REDIS_DOCKER_IMAGE)) + .withExposedPorts(6379) + .withReuse(true); + + REDIS_CONTAINER.start(); // (2) + + // (3) + System.setProperty("spring.data.redis.host", REDIS_CONTAINER.getHost()); + System.setProperty("spring.data.redis.port", REDIS_CONTAINER.getMappedPort(6379).toString()); + } +} diff --git a/src/test/resources/docker-compose.yml b/src/test/resources/docker-compose.yml new file mode 100644 index 0000000..a9ca786 --- /dev/null +++ b/src/test/resources/docker-compose.yml @@ -0,0 +1,8 @@ +version: "3" + +services: + redis: + image: redis:7 + command: redis-server --port 6379 + ports: + - "6380:6379"