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

When an image version is not specified, use latest as the default tag #3313

Merged
merged 4 commits into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/main/java/org/testcontainers/utility/Versioning.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public boolean isValid() {

@Override
public String getSeparator() {
return "";
return ":";
}

@Override
public String toString() {
return "";
return "latest";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.testcontainers.dockerclient;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.model.Image;
import org.junit.Test;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy;
import org.testcontainers.utility.DockerImageName;

import java.util.List;

public class AmbiguousImagePullTest {

@Test(timeout = 30_000)
public void testNotUsingParse() {
DockerClient client = DockerClientFactory.instance().client();
List<Image> alpineImages = client.listImagesCmd()
.withImageNameFilter("alpine:latest")
.exec();
for (Image alpineImage : alpineImages) {
client.removeImageCmd(alpineImage.getId()).exec();
}

try (
final GenericContainer<?> container = new GenericContainer<>(DockerImageName.parse("alpine"))
.withCommand("/bin/sh", "-c", "sleep 0")
.withStartupCheckStrategy(new OneShotStartupCheckStrategy())
) {
container.start();
// do nothing other than start and stop
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void testParsing() {
canonicalName = unversionedPart + versionSeparator + version;
} else {
combined = unversionedPart;
canonicalName = unversionedPart;
canonicalName = unversionedPart + ":latest";
}

VisibleAssertions.context("For " + combined);
Expand All @@ -124,7 +124,7 @@ public void testParsing() {
if (version != null) {
assertEquals(combined + " has version part: " + version, version, imageName.getVersionPart());
} else {
assertEquals(combined + " has no version specified", "", imageName.getVersionPart());
assertEquals(combined + " has automatic 'latest' version specified", "latest", imageName.getVersionPart());
}
assertEquals(combined + " has canonical name: " + canonicalName, canonicalName, imageName.asCanonicalNameString());

Expand Down