Skip to content

Commit

Permalink
Improve Docker Compose error messaging (#2154)
Browse files Browse the repository at this point in the history
Co-Authored-By: Richard North <rich.north@gmail.com>
Co-authored-by: Matthias Hahn <mhahn@etracker.com>
Co-authored-by: null <38075918+HaMatthias@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 6, 2019
1 parent bb0554b commit 500fd74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Expand Up @@ -385,7 +385,15 @@ public String getServiceHost(String serviceName, Integer servicePort) {
* @return a port that can be used for accessing the service container.
*/
public Integer getServicePort(String serviceName, Integer servicePort) {
return ambassadorContainer.getMappedPort(ambassadorPortMappings.get(getServiceInstanceName(serviceName)).get(servicePort));
Map<Integer, Integer> portMap = ambassadorPortMappings.get(getServiceInstanceName(serviceName));

if (portMap == null) {
throw new IllegalArgumentException("Could not get a port for '" + serviceName + "'. " +
"Testcontainers does not have an exposed port configured for '" + serviceName + "'. "+
"To fix, please ensure that the service '" + serviceName + "' has ports exposed using .withExposedService(...)");
} else {
return ambassadorContainer.getMappedPort(portMap.get(servicePort));
}
}

public SELF withScaledService(String serviceBaseName, int numInstances) {
Expand Down
Expand Up @@ -21,7 +21,7 @@ protected DockerComposeContainer getEnvironment() {
return environment;
}

@Test(expected = NullPointerException.class)
@Test(expected = IllegalArgumentException.class)
public void testDbIsNotStarting() {
environment.getServicePort("db_1", 10001);
}
Expand Down

0 comments on commit 500fd74

Please sign in to comment.