Skip to content

Commit

Permalink
Add custom exception message when HealthState not present in response (
Browse files Browse the repository at this point in the history
  • Loading branch information
pivovarit authored and quincy committed May 28, 2020
1 parent 75e512d commit 90f2a98
Showing 1 changed file with 6 additions and 2 deletions.
@@ -1,6 +1,7 @@
package org.testcontainers.containers;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.HealthState;
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.exception.DockerException;
import com.github.dockerjava.api.model.ExposedPort;
Expand Down Expand Up @@ -89,9 +90,12 @@ default boolean isHealthy() {

try {
InspectContainerResponse inspectContainerResponse = getCurrentContainerInfo();
String healthStatus = inspectContainerResponse.getState().getHealth().getStatus();
HealthState health = inspectContainerResponse.getState().getHealth();
if (health == null) {
throw new RuntimeException("This container's image does not have a healthcheck declared, so health cannot be determined. Either amend the image or use another approach to determine whether containers are healthy.");
}

return healthStatus.equals(STATE_HEALTHY);
return STATE_HEALTHY.equals(health.getStatus());
} catch (DockerException e) {
return false;
}
Expand Down

0 comments on commit 90f2a98

Please sign in to comment.