summaryrefslogtreecommitdiffstats
path: root/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImageGarbageCollectionTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImageGarbageCollectionTest.java')
-rw-r--r--docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImageGarbageCollectionTest.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImageGarbageCollectionTest.java b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImageGarbageCollectionTest.java
index 520f8a74d58..412b8301e4c 100644
--- a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImageGarbageCollectionTest.java
+++ b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImageGarbageCollectionTest.java
@@ -50,7 +50,7 @@ public class DockerImageGarbageCollectionTest {
@Test
public void singleImageWithContainerIsUsed() {
gcTester.withExistingImages(ImageBuilder.forId("image-1"))
- .andExistingContainers(new ContainerLite("container-1", "image-1", "running"))
+ .andExistingContainers(ContainerBuilder.forId("container-1").withImageId("image-1"))
.expectDeletedImages();
}
@@ -77,7 +77,7 @@ public class DockerImageGarbageCollectionTest {
ImageBuilder.forId("parent-image"),
ImageBuilder.forId("image-1").withParentId("parent-image").withTags("latest"),
ImageBuilder.forId("image-2").withParentId("parent-image").withTags("1.24"))
- .andExistingContainers(new ContainerLite("vespa-node-1", "image-1", "running"))
+ .andExistingContainers(ContainerBuilder.forId("vespa-node-1").withImageId("image-1"))
.expectDeletedImages("1.24"); // Deleting the only tag will delete the image
}
@@ -173,8 +173,10 @@ public class DockerImageGarbageCollectionTest {
return this;
}
- private ImageGcTester andExistingContainers(ContainerLite... containers) {
- when(docker.listAllContainers()).thenReturn(List.of(containers));
+ private ImageGcTester andExistingContainers(ContainerBuilder... containers) {
+ when(docker.listAllContainers()).thenReturn(Arrays.stream(containers)
+ .map(ContainerBuilder::toContainer)
+ .collect(Collectors.toList()));
return this;
}
@@ -255,4 +257,22 @@ public class DockerImageGarbageCollectionTest {
private ImageBuilder withTags(String... tags) { this.repoTags = tags; return this; }
private Image toImage() { return createFrom(Image.class, this); }
}
+
+ // Workaround for Container class that can't be instantiated directly in Java (instantiate via Jackson instead).
+ private static class ContainerBuilder {
+ // Json property names must match exactly the property names in the Container class.
+ @JsonProperty("Id")
+ private final String id;
+
+ @JsonProperty("ImageID")
+ private String imageId;
+
+ private ContainerBuilder(String id) { this.id = id; }
+ private static ContainerBuilder forId(final String id) { return new ContainerBuilder(id); }
+ private ContainerBuilder withImageId(String imageId) { this.imageId = imageId; return this; }
+
+ private com.github.dockerjava.api.model.Container toContainer() {
+ return createFrom(com.github.dockerjava.api.model.Container.class, this);
+ }
+ }
}