GoodforGod / arangodb-testcontainers

⚙️ TestContainers ArangoDB module implementation.
https://testcontainers.com/modules/arangodb/
MIT License
12 stars 1 forks source link

Add @ServiceConnection support (for Spring Boot 3.X) #12

Open Steve973 opened 6 months ago

Steve973 commented 6 months ago

Please add @ServiceConnection support for Spring Boot 3.X. You can read more, and see an example here: https://spring.io/blog/2023/06/23/improved-testcontainers-support-in-spring-boot-3-1

Currently, I can add a @DynamicPropertySource method that accepts the DynamicPropertyRegistry instance, where we can add the connection details properties like this:

  @DynamicPropertySource
  static void arangoProperties(DynamicPropertyRegistry registry) {
    registry.add(
        "arangodb.spring.data.hosts",
        () -> String.format("%s:%d", arango.getHost(), arango.getMappedPort(8529)));
    registry.add("arangodb.spring.data.password", () -> "test");
  }

It works, but the newer and cleaner way is to be able to annotate the container instance with @ServiceConnection, like this:

  @Container
  @ServiceConnection
  private static final ArangoContainer<?> arango =
      new ArangoContainer<>(DockerImageName.parse("arangodb:3.11"))
          .withPassword("test")
          .withExposedPorts(8529)
          .waitingFor(Wait.forListeningPort())
          .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(BasicDataLayerIT.class)));

With this method, we no longer need to use @DynamicPropertySource.

GoodforGod commented 5 months ago

Hello @Steve973 , I'll look into it and will back with update

Steve973 commented 5 months ago

Thanks for looking into this. I could also help if you would want. Another thing you might consider is making the arango container class not have a parameter since you can't do anything with it anyway. The way that most of the other implementations work, they don't expose that self-parameter to the user.