Skip to content

Commit 7e24a13

Browse files
committed
Restore original pull/push expected exception logic
1 parent 798117f commit 7e24a13

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

src/test/java/com/github/dockerjava/cmd/PullImageCmdIT.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.github.dockerjava.api.exception.NotFoundException;
88
import com.github.dockerjava.api.model.Info;
99
import com.github.dockerjava.api.model.PullResponseItem;
10+
import com.github.dockerjava.core.RemoteApiVersion;
1011
import com.github.dockerjava.core.command.PullImageCmdImpl;
1112
import com.github.dockerjava.core.command.PullImageResultCallback;
1213
import org.junit.Rule;
@@ -17,9 +18,9 @@
1718

1819
import java.util.concurrent.TimeUnit;
1920

21+
import static com.github.dockerjava.utils.TestUtils.getVersion;
22+
import static com.github.dockerjava.utils.TestUtils.isNotSwarm;
2023
import static org.hamcrest.MatcherAssert.assertThat;
21-
import static org.hamcrest.Matchers.anyOf;
22-
import static org.hamcrest.Matchers.instanceOf;
2324
import static org.hamcrest.Matchers.lessThanOrEqualTo;
2425
import static org.hamcrest.Matchers.notNullValue;
2526
import static org.junit.Assert.assertEquals;
@@ -96,8 +97,12 @@ public void testPullImage() throws Exception {
9697

9798
@Test
9899
public void testPullNonExistingImage() throws Exception {
99-
//different docker version throws different errors here
100-
exception.expect(anyOf(instanceOf(NotFoundException.class), instanceOf(DockerClientException.class)));
100+
if (isNotSwarm(dockerRule.getClient()) && getVersion(dockerRule.getClient())
101+
.isGreaterOrEqual(RemoteApiVersion.VERSION_1_26)) {
102+
exception.expect(NotFoundException.class);
103+
} else {
104+
exception.expect(DockerClientException.class);
105+
}
101106

102107
// stream needs to be fully read in order to close the underlying connection
103108
dockerRule.getClient().pullImageCmd("xvxcv/foo")

src/test/java/com/github/dockerjava/cmd/PushImageCmdIT.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.github.dockerjava.api.command.CreateContainerResponse;
44
import com.github.dockerjava.api.exception.DockerClientException;
55
import com.github.dockerjava.api.exception.NotFoundException;
6+
import com.github.dockerjava.core.RemoteApiVersion;
67
import com.github.dockerjava.core.command.PullImageResultCallback;
78
import com.github.dockerjava.core.command.PushImageResultCallback;
89
import com.github.dockerjava.junit.category.AuthIntegration;
@@ -16,9 +17,9 @@
1617

1718
import java.util.concurrent.TimeUnit;
1819

20+
import static com.github.dockerjava.utils.TestUtils.getVersion;
21+
import static com.github.dockerjava.utils.TestUtils.isNotSwarm;
1922
import static org.hamcrest.MatcherAssert.assertThat;
20-
import static org.hamcrest.Matchers.anyOf;
21-
import static org.hamcrest.Matchers.instanceOf;
2223
import static org.hamcrest.Matchers.isEmptyString;
2324
import static org.hamcrest.Matchers.not;
2425

@@ -62,11 +63,17 @@ public void pushLatest() throws Exception {
6263

6364
@Test
6465
public void pushNonExistentImage() throws Exception {
65-
//swarms throws a different error here
66-
exception.expect(anyOf(instanceOf(DockerClientException.class), instanceOf(NotFoundException.class)));
66+
67+
if (isNotSwarm(dockerRule.getClient()) && getVersion(dockerRule.getClient())
68+
.isGreaterOrEqual(RemoteApiVersion.VERSION_1_24)) {
69+
exception.expect(DockerClientException.class);
70+
} else {
71+
exception.expect(NotFoundException.class);
72+
}
6773

6874
dockerRule.getClient().pushImageCmd(username + "/xxx")
6975
.exec(new PushImageResultCallback())
70-
.awaitCompletion(30, TimeUnit.SECONDS);
76+
.awaitCompletion(30, TimeUnit.SECONDS); // exclude infinite await sleep
77+
7178
}
7279
}

0 commit comments

Comments
 (0)