Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Comment thread
rnorth marked this conversation as resolved.
public void testDbIsNotStarting() {
environment.getServicePort("db_1", 10001);
}

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