Skip to content

Commit 07a7d57

Browse files
committed
doesnt work - jupiter always calls after anyway
1 parent ef4faaa commit 07a7d57

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

docker-compose-junit-jupiter/src/integrationTest/java/com/palantir/docker/compose/DockerComposeExtensionIntegrationTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,10 @@ public void an_external_port_exists() {
4949
public void container_stays_up_between_tests() {
5050
assertThat(docker.containers().container("db").port(5432).getExternalPort()).isEqualTo(port);
5151
}
52+
53+
@Test
54+
@Order(3)
55+
public void calls_after_on_exception() {
56+
assertThat(docker.containers().container("db").port(5432).getExternalPort()).isEqualTo(port);
57+
}
5258
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.palantir.docker.compose;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
import com.palantir.docker.compose.configuration.DockerComposeFiles;
22+
import com.palantir.docker.compose.connection.State;
23+
import com.palantir.docker.compose.connection.waiting.HealthChecks;
24+
import java.io.IOException;
25+
import org.joda.time.Duration;
26+
import org.junit.jupiter.api.Order;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.api.extension.RegisterExtension;
29+
30+
public class DockerComposeExtensionIntegrationTestWithFailingCommand {
31+
32+
@RegisterExtension
33+
public static final DockerComposeExtension docker = DockerComposeExtension.builder()
34+
.files(DockerComposeFiles.from("src/integrationTest/resources/docker-compose-with-failing-command"
35+
+ ".yaml"))
36+
.waitingForService("cmd", HealthChecks.toRespondOverHttp(9999, _$ -> "http://will-fail"),
37+
Duration.millis(50))
38+
.build();
39+
40+
@Test
41+
@Order(1)
42+
public void calls_after_on_exception() throws IOException, InterruptedException {
43+
assertThat(docker.containers().container("cmd").state()).isEqualTo(State.DOWN);
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cmd:
2+
image: appropriate/nc
3+
command: /bin/sh -c 'sleep 1000'
4+
ports:
5+
- "9999:9999"

docker-compose-junit-jupiter/src/main/java/com/palantir/docker/compose/DockerComposeExtension.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ public abstract class DockerComposeExtension extends DockerComposeManager
3232

3333
@Override
3434
public void beforeAll(ExtensionContext unused) throws IOException, InterruptedException {
35-
before();
35+
try {
36+
before();
37+
} catch (RuntimeException e) {
38+
after();
39+
throw e;
40+
}
3641
}
3742

3843
@Override

docker-compose-rule-core/src/main/java/com/palantir/docker/compose/connection/Container.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public DockerPort port(int internalPort) {
8888
.stream()
8989
.filter(port -> port.getInternalPort() == internalPort)
9090
.findFirst()
91-
.orElseThrow(() -> new IllegalArgumentException("No internal port '" + internalPort + "' for container '" + containerName + "': " + portMappings));
91+
.orElseThrow(() -> new IllegalArgumentException("No internal port '" + internalPort + "' "
92+
+ "for container '" + containerName + "': " + portMappings.get()));
9293
}
9394

9495
public void start() throws IOException, InterruptedException {

0 commit comments

Comments
 (0)