Skip to content

Commit

Permalink
doesnt work - jupiter always calls after anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
pnepywoda committed Oct 16, 2019
1 parent ef4faaa commit 1bcdf1a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ public void an_external_port_exists() {
public void container_stays_up_between_tests() {
assertThat(docker.containers().container("db").port(5432).getExternalPort()).isEqualTo(port);
}

@Test
@Order(3)
public void calls_after_on_exception() {
assertThat(docker.containers().container("db").port(5432).getExternalPort()).isEqualTo(port);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.docker.compose;

import static org.assertj.core.api.Assertions.assertThat;

import com.palantir.docker.compose.configuration.DockerComposeFiles;
import com.palantir.docker.compose.connection.State;
import com.palantir.docker.compose.connection.waiting.HealthChecks;
import java.io.IOException;
import org.joda.time.Duration;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class DockerComposeExtensionIntegrationTestWithFailingCommand {

@RegisterExtension
public static final DockerComposeExtension docker = DockerComposeExtension.builder()
.files(DockerComposeFiles.from("src/integrationTest/resources/docker-compose-with-failing-command"
+ ".yaml"))
.waitingForService("cmd", HealthChecks.toRespondOverHttp(9999, _$ -> "http://will-fail"),
Duration.millis(50))
.build();

@Test
@Order(1)
public void calls_after_on_exception() throws IOException, InterruptedException {
assertThat(docker.containers().container("cmd").state()).isEqualTo(State.DOWN);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmd:
image: appropriate/nc
command: /bin/sh -c 'sleep 1000'
ports:
- "9999:9999"
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public abstract class DockerComposeExtension extends DockerComposeManager

@Override
public void beforeAll(ExtensionContext unused) throws IOException, InterruptedException {
before();
try {
before();
} catch (RuntimeException e) {
// after();
throw e;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public DockerPort port(int internalPort) {
.stream()
.filter(port -> port.getInternalPort() == internalPort)
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("No internal port '" + internalPort + "' for container '" + containerName + "': " + portMappings));
.orElseThrow(() -> new IllegalArgumentException("No internal port '" + internalPort + "' "
+ "for container '" + containerName + "': " + portMappings.get()));
}

public void start() throws IOException, InterruptedException {
Expand Down

0 comments on commit 1bcdf1a

Please sign in to comment.