Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]: Override toString() for ChainedImageNameSubstitutor to return type of "wrapped" ImageNameSubstitutor #7039

Closed
jxblum opened this issue May 13, 2023 · 2 comments · Fixed by #7522

Comments

@jxblum
Copy link

jxblum commented May 13, 2023

Module

Core

Proposal

If users configure a custom ImageNameSubstitutor (for example), then this instance will get wrapped by Testcontainers when the configuration is evaluated.

If an error occurs, regardless of context (in my case, I am using Spring) then the "configured" ImageNameSubstitutor in the RemoteDockerImage instance created from an DockerImageName by the container, is quite "cryptic":

2023-05-13 02:44:13,155 ERROR g.springframework.boot.SpringApplication: 822 - Application run failed
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'CassandraContainer' defined in example.app.crm.config.TestcontainersCassandraConfiguration: 
Failed to instantiate [org.testcontainers.containers.GenericContainer]: Factory method 'cassandraContainer' threw exception with message: 
Can't get Docker image: RemoteDockerImage(
  imageName=cassandra:3.11.15, 
  imagePullPolicy=DefaultPullPolicy(), 
  imageNameSubstitutor=org.testcontainers.utility.ImageNameSubstitutor$ChainedImageNameSubstitutor@4904144d
)

It is not apparent from this ERROR log output whether the custom ImageNameSubstitutor was actually in use here, and users have to make an effort (logging, debugging, etc) to determine if the custom ImageNameSubstitutor was actually applied or not.

In my case, I had to add logging to my "custom" ImageNameSubstitutor to determine whether it was actually being applied and used by Testcontainers during Docker Image Name resolution since my library was being built remotely in a Jenkins CI environment where debugging is nearly impossible.

This:

imageNameSubstitutor=org.testcontainers.utility.ImageNameSubstitutor$ChainedImageNameSubstitutor@4904144d

... is quite useless.

The toString() method of the static inner ChainedImageNameSubstitutor class (source) could be overridden to return getDescription() (source).

Altneratively, the ImageNameSubstitutor abstract class could override the toString() method to return getDescription(), like so:

abstract class ImageNameSubstitutor {

  @Override
  public String toString() {
    return getDescription();
  }
}

In this way, all extensions of ImageNameSubstitutor would benefit and also be consistent without any extra effort on behalf of your users.

eddumelendez added a commit that referenced this issue Sep 10, 2023
Returns ChainedImageNameSubstitutor's getDescription

Fixes #7039
eddumelendez added a commit that referenced this issue Sep 13, 2023
Returns ChainedImageNameSubstitutor's getDescription

Fixes #7039
@eddumelendez
Copy link
Member

Hi @jxblum, Testcontainers for Java 1.19.1 was just released and contains this change. Thanks for the report.

@jxblum
Copy link
Author

jxblum commented Oct 2, 2023

Hi @eddumelendez - Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants