Skip to content

Commit

Permalink
feat: redis test container 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
govl6113 committed Nov 6, 2023
1 parent d692c21 commit 4af803e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
8 changes: 8 additions & 0 deletions src/test/resources/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3"

services:
redis:
image: redis:7
command: redis-server --port 6379
ports:
- "6380:6379"

0 comments on commit 4af803e

Please sign in to comment.