Skip to content

Commit

Permalink
image URL without tag formatted by Image object shouldn't have traili…
Browse files Browse the repository at this point in the history
…ng colon

Before this the returned URL was `quay.io/jaegertracing/all-in-one:1.56:`.
  • Loading branch information
simkam authored and mnovak committed Oct 3, 2024
1 parent 31868e6 commit 369d110
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/cz/xtf/core/image/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static Image from(String imageUrl) {
private final String tag;

public Image(String registry, String user, String repo, String tag) {
this.url = String.format("%s/%s/%s:%s", registry, user, repo, tag);
this.url = String.format(tag.trim().isEmpty() ? "%s/%s/%s" : "%s/%s/%s:%s", registry, user, repo, tag);
this.registry = registry;
this.user = user;
this.repo = repo;
Expand Down
12 changes: 12 additions & 0 deletions core/src/test/java/cz/xtf/core/image/ImageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ public void testImageFromUrlThreeTokens() {
Assertions.assertEquals("jaegertracing", image.getUser(), "Wrong user parsed from image url.");
Assertions.assertEquals("all-in-one", image.getRepo(), "Wrong repository name.");
Assertions.assertEquals("1.56", image.getTag(), "Wrong tag parsed from image url.");
Assertions.assertEquals("quay.io/jaegertracing/all-in-one:1.56", image.getUrl(),
"Wrong url generated from image object.");
}

@Test
public void testImageFromUrlThreeTokensNoTag() {
Image image = Image.from("quay.io/jaegertracing/all-in-one");
Assertions.assertEquals("quay.io", image.getRegistry(), "Wrong registry parsed from image url.");
Assertions.assertEquals("jaegertracing", image.getUser(), "Wrong user parsed from image url.");
Assertions.assertEquals("all-in-one", image.getRepo(), "Wrong repository name.");
Assertions.assertEquals("", image.getTag(), "Wrong tag parsed from image url.");
Assertions.assertEquals("quay.io/jaegertracing/all-in-one", image.getUrl(), "Wrong url generated from image object.");
}

@Test
Expand Down

0 comments on commit 369d110

Please sign in to comment.