forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPullImageCmdIT.java
More file actions
165 lines (130 loc) · 6.21 KB
/
Copy pathPullImageCmdIT.java
File metadata and controls
165 lines (130 loc) · 6.21 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.github.dockerjava.cmd;
import com.github.dockerjava.api.command.InspectImageResponse;
import com.github.dockerjava.api.exception.DockerClientException;
import com.github.dockerjava.api.exception.DockerException;
import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.Info;
import com.github.dockerjava.core.RemoteApiVersion;
import com.github.dockerjava.junit.PrivateRegistryRule;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
import static com.github.dockerjava.utils.TestUtils.getVersion;
import static com.github.dockerjava.utils.TestUtils.isNotSwarm;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.notNullValue;
public class PullImageCmdIT extends CmdIT {
private static final Logger LOG = LoggerFactory.getLogger(PullImageCmdIT.class);
@ClassRule
public static PrivateRegistryRule REGISTRY = new PrivateRegistryRule();
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
public void testPullImage() throws Exception {
Info info = dockerRule.getClient().infoCmd().exec();
LOG.info("Client info: {}", info.toString());
int imgCount = info.getImages();
LOG.info("imgCount1: {}", imgCount);
// This should be an image that is not used by other repositories
// already
// pulled down, preferably small in size. If tag is not used pull will
// download all images in that repository but tmpImgs will only
// deleted 'latest' image but not images with other tags
String testImage = "hackmann/empty";
LOG.info("Removing image: {}", testImage);
try {
dockerRule.getClient().removeImageCmd(testImage).withForce(true).exec();
} catch (NotFoundException e) {
// just ignore if not exist
}
info = dockerRule.getClient().infoCmd().exec();
LOG.info("Client info: {}", info.toString());
imgCount = info.getImages();
LOG.info("imgCount2: {}", imgCount);
LOG.info("Pulling image: {}", testImage);
dockerRule.getClient().pullImageCmd(testImage)
.start()
.awaitCompletion(30, TimeUnit.SECONDS);
info = dockerRule.getClient().infoCmd().exec();
LOG.info("Client info after pull, {}", info.toString());
assertThat(imgCount, lessThanOrEqualTo(info.getImages()));
InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(testImage).exec();
LOG.info("Image Inspect: {}", inspectImageResponse.toString());
assertThat(inspectImageResponse, notNullValue());
}
@Test
public void testPullNonExistingImage() throws Exception {
if (isNotSwarm(dockerRule.getClient()) && getVersion(dockerRule.getClient())
.isGreaterOrEqual(RemoteApiVersion.VERSION_1_26)) {
exception.expect(NotFoundException.class);
} else {
exception.expect(DockerClientException.class);
}
// stream needs to be fully read in order to close the underlying connection
dockerRule.getClient().pullImageCmd("xvxcv/foo")
.start()
.awaitCompletion(30, TimeUnit.SECONDS);
}
@Test
public void testPullImageWithValidAuth() throws Exception {
AuthConfig authConfig = REGISTRY.getAuthConfig();
String imgName = REGISTRY.createPrivateImage("pull-image-with-valid-auth");
// stream needs to be fully read in order to close the underlying connection
dockerRule.getClient().pullImageCmd(imgName)
.withAuthConfig(authConfig)
.start()
.awaitCompletion(30, TimeUnit.SECONDS);
}
@Test
public void testPullImageWithValidAuthAndEmail() throws Exception {
AuthConfig authConfig = REGISTRY.getAuthConfig().withEmail("foo@bar.de");
String imgName = REGISTRY.createPrivateImage("pull-image-with-valid-auth");
// stream needs to be fully read in order to close the underlying connection
dockerRule.getClient().pullImageCmd(imgName)
.withAuthConfig(authConfig)
.start()
.awaitCompletion(30, TimeUnit.SECONDS);
}
@Test
public void testPullImageWithNoAuth() throws Exception {
AuthConfig authConfig = REGISTRY.getAuthConfig();
String imgName = REGISTRY.createPrivateImage("pull-image-with-no-auth");
if (isNotSwarm(dockerRule.getClient()) && getVersion(dockerRule.getClient())
.isGreaterOrEqual(RemoteApiVersion.VERSION_1_30)) {
exception.expect(DockerException.class);
} else {
exception.expect(DockerClientException.class);
}
// stream needs to be fully read in order to close the underlying connection
dockerRule.getClient().pullImageCmd(imgName)
.start()
.awaitCompletion(30, TimeUnit.SECONDS);
}
@Test
public void testPullImageWithInvalidAuth() throws Exception {
AuthConfig authConfig = REGISTRY.getAuthConfig();
AuthConfig invalidAuthConfig = new AuthConfig()
.withUsername("testuser")
.withPassword("testwrongpassword")
.withEmail("foo@bar.de")
.withRegistryAddress(authConfig.getRegistryAddress());
String imgName = REGISTRY.createPrivateImage("pull-image-with-invalid-auth");
if (isNotSwarm(dockerRule.getClient()) && getVersion(dockerRule.getClient())
.isGreaterOrEqual(RemoteApiVersion.VERSION_1_30)) {
exception.expect(DockerException.class);
} else {
exception.expect(DockerClientException.class);
}
// stream needs to be fully read in order to close the underlying connection
dockerRule.getClient().pullImageCmd(imgName)
.withAuthConfig(invalidAuthConfig)
.start()
.awaitCompletion(30, TimeUnit.SECONDS);
}
}