forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadImageCmdIT.java
More file actions
64 lines (52 loc) · 2.1 KB
/
Copy pathLoadImageCmdIT.java
File metadata and controls
64 lines (52 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.github.dockerjava.cmd;
import com.github.dockerjava.api.model.Image;
import com.github.dockerjava.utils.TestResources;
import net.jcip.annotations.NotThreadSafe;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.List;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.notNullValue;
@NotThreadSafe
public class LoadImageCmdIT extends CmdIT {
private String expectedImageId;
@Before
public void beforeMethod() {
expectedImageId = "sha256:56031f66eb0cef2e2e5cb2d1dabafaa0ebcd0a18a507d313b5bdb8c0472c5eba";
if (findImageWithId(expectedImageId, dockerRule.getClient().listImagesCmd().exec()) != null) {
dockerRule.getClient().removeImageCmd(expectedImageId).exec();
}
}
@After
public void afterMethod() {
dockerRule.getClient().removeImageCmd(expectedImageId).exec();
}
@Test
public void loadImageFromTar() throws Exception {
try (InputStream uploadStream = Files.newInputStream(TestResources.getApiImagesLoadTestTarball())) {
dockerRule.getClient().loadImageCmd(uploadStream).exec();
}
//swarm needs some time to reflect new images
synchronized (this) {
wait(5000);
}
final Image image = findImageWithId(expectedImageId, dockerRule.getClient().listImagesCmd().exec());
assertThat("Can't find expected image after loading from a tar archive!", image, notNullValue());
assertThat("Image after loading from a tar archive has wrong tags!",
asList(image.getRepoTags()), equalTo(singletonList("docker-java/load:1.0")));
}
private Image findImageWithId(final String id, final List<Image> images) {
for (Image image : images) {
if (id.equals(image.getId())) {
return image;
}
}
return null;
}
}