spring-projects / spring-projects/spring-boot

Support ComposeContainer and DockerComposeContainer in Testcontainers integration

Open
#43,174 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

I'd like to define a new ConnectionDetails type for https://github.com/eclipse/kapua .
Eclipse Kapua can only be run via Docker compose. To achieve that, I run it successfully via org.testcontainers.containers.DockerComposeContainer.

I added a KapuaConnectionDetails:

public interface KapuaConnectionDetails extends ConnectionDetails {

  String baseHttpUrl();
}

I would have expected to be able to plug DockerComposeContainer as source of ContainerConnectionDetailsFactory.

But the current signature of ContainerConnectionDetailsFactory is:

public abstract class ContainerConnectionDetailsFactory<C extends Container<?>, D extends ConnectionDetails>
		implements ConnectionDetailsFactory<ContainerConnectionSource<C>, D> {}

Because of that, C excludes org.testcontainers.containers.DockerComposeContainer.

By looking at ContainerConnectionDetailsFactory, I didn't find a good reason for why C is restricted to Container<?>. ContainerConnectionDetailsFactory and its dependencies do not use Container<?>'s method. The only used method is from Startable, and it is only used after a cast check:

https://github.com/spring-projects/spring-boot/blob/c6619dd306b844ad7f876a9a7abc3661cc343dd1/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactory.java#L190-L192

Could we relax C restriction to allow DockerComposeContainer usage?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactory.java, especially the cast check around lines 190–192. Trace the generic type through its dependencies and assess support for DockerComposeContainer and ComposeContainer; done means both can serve as sources for a ContainerConnectionDetailsFactory without breaking existing container support.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.