Skip to content

Commit

Permalink
Fix regression using GenericContainer#setImage (#7820)
Browse files Browse the repository at this point in the history
1dba8d1 introduced a breaking change. `GenericContainer#getImage`
returns the value of `ContainerDef#getImage` instead of `RemoteImageName`
because this is not set anymore when using `GenericContainer#setImage`.

Fixes #7819
  • Loading branch information
eddumelendez authored Nov 18, 2023
1 parent b59888a commit f1f79dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public GenericContainer(@NonNull final Future<String> image) {
}

public void setImage(Future<String> image) {
this.image = new RemoteDockerImage(image);
this.containerDef.setImage(new RemoteDockerImage(image));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.testcontainers.TestImages;
import org.testcontainers.containers.startupcheck.StartupCheckStrategy;
import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;
import org.testcontainers.images.RemoteDockerImage;
import org.testcontainers.images.builder.ImageFromDockerfile;
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.utility.MountableFile;
Expand Down Expand Up @@ -222,6 +223,14 @@ public void testArchitectureCheck() {
}
}

@Test
public void shouldReturnTheProvidedImage() {
GenericContainer container = new GenericContainer(TestImages.REDIS_IMAGE);
assertThat(container.getImage().get()).isEqualTo("redis:3.0.2");
container.setImage(new RemoteDockerImage(TestImages.ALPINE_IMAGE));
assertThat(container.getImage().get()).isEqualTo("alpine:3.16");
}

static class NoopStartupCheckStrategy extends StartupCheckStrategy {

@Override
Expand Down

0 comments on commit f1f79dc

Please sign in to comment.