Skip to content

Commit

Permalink
Polish support for Testcontainers Redis
Browse files Browse the repository at this point in the history
- Add support for RedisStackContainer
- Update the docs

Closes gh-41450
  • Loading branch information
wilkinsona committed Sep 5, 2024
1 parent 7deb74a commit f7ba5f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The following service connection factories are provided in the `spring-boot-test
| Containers of type `RabbitMQContainer`

| `RedisConnectionDetails`
| Containers named "redis", "redis/redis-stack" or "redis/redis-stack-server"
| Containers of type `com.redis.testcontainers.RedisContainer` or `com.redis.testcontainers.RedisStackContainer`, or containers named "redis", "redis/redis-stack" or "redis/redis-stack-server"

| `ZipkinConnectionDetails`
| Containers named "openzipkin/zipkin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;

import com.redis.testcontainers.RedisContainer;
import com.redis.testcontainers.RedisStackContainer;
import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails;
Expand All @@ -32,7 +33,7 @@
import static org.assertj.core.api.Assertions.assertThat;

/**
* Test for {@link RedisContainerConnectionDetailsFactory} when using a custom contain
* Test for {@link RedisContainerConnectionDetailsFactory} when using a custom container
* without "redis" as the name.
*
* @author Phillip Webb
Expand All @@ -50,4 +51,15 @@ void getConnectionDetailsWhenRedisContainerWithCustomName() {
assertThat(connectionDetails.get(RedisConnectionDetails.class)).isNotNull();
}

@Test
void getConnectionDetailsWhenRedisStackContainerWithCustomName() {
ConnectionDetailsFactories factories = new ConnectionDetailsFactories();
MergedAnnotation<ServiceConnection> annotation = MergedAnnotation.of(ServiceConnection.class,
Map.of("value", ""));
ContainerConnectionSource<RedisStackContainer> source = TestContainerConnectionSource.create("test", null,
RedisStackContainer.class, "mycustomimage", annotation, null);
Map<Class<?>, ConnectionDetails> connectionDetails = factories.getConnectionDetails(source, true);
assertThat(connectionDetails.get(RedisConnectionDetails.class)).isNotNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;

import com.redis.testcontainers.RedisContainer;
import com.redis.testcontainers.RedisStackContainer;
import org.testcontainers.containers.Container;
import org.testcontainers.containers.GenericContainer;

Expand Down Expand Up @@ -53,7 +54,8 @@ class RedisContainerConnectionDetailsFactory
protected boolean sourceAccepts(ContainerConnectionSource<Container<?>> source, Class<?> requiredContainerType,
Class<?> requiredConnectionDetailsType) {
return super.sourceAccepts(source, requiredContainerType, requiredConnectionDetailsType)
|| source.accepts(ANY_CONNECTION_NAME, RedisContainer.class, requiredConnectionDetailsType);
|| source.accepts(ANY_CONNECTION_NAME, RedisContainer.class, requiredConnectionDetailsType)
|| source.accepts(ANY_CONNECTION_NAME, RedisStackContainer.class, requiredConnectionDetailsType);
}

@Override
Expand Down

0 comments on commit f7ba5f1

Please sign in to comment.