Skip to content

Commit

Permalink
Docker Compose: allow specific services to be started (#1528)
Browse files Browse the repository at this point in the history
  • Loading branch information
HaMatthias authored and rnorth committed Jul 6, 2019
1 parent 06ea95b commit 7fae384
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class DockerComposeContainer<SELF extends DockerComposeContainer<SELF>> e

private static final Object MUTEX = new Object();

private List<String> services = new ArrayList<>();

/**
* Properties that should be passed through to all Compose and ambassador containers (not
* necessarily to containers that are spawned by Compose itself)
Expand Down Expand Up @@ -159,10 +161,18 @@ private void pullImages() {
runWithCompose("pull");
}

public SELF withServices(@NonNull String... services) {
this.services = Arrays.asList(services);
return self();
}

private void createServices() {
// Run the docker-compose container, which starts up the services
runWithCompose("up -d");
if(services.isEmpty()) {
runWithCompose("up -d");
} else {
runWithCompose("up -d " + String.join(" ", services));
}
}

private void waitUntilServiceStarted() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.testcontainers.junit;

import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.DockerComposeContainer;

import static org.rnorth.visibleassertions.VisibleAssertions.assertNotNull;

import java.io.File;

public class DockerComposeServiceTest extends BaseDockerComposeTest {

@Rule
public DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
.withServices("redis")
.withExposedService("redis_1", REDIS_PORT);


@Override
protected DockerComposeContainer getEnvironment() {
return environment;
}

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

@Test
public void testRedisIsStarting() {
assertNotNull("Redis server started", environment.getServicePort("redis_1", REDIS_PORT));
}
}

0 comments on commit 7fae384

Please sign in to comment.