Skip to content

Commit

Permalink
Support TmpFS mappings (#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
malltshik authored and rnorth committed Dec 23, 2018
1 parent b5f4d8a commit ef7c516
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ public class GenericContainer<SELF extends GenericContainer<SELF>>
.withConstantThroughput()
.build();

@Nullable
private Map<String, String> tmpFsMapping;


public GenericContainer() {
this(TestcontainersConfiguration.getInstance().getTinyImage());
Expand Down Expand Up @@ -292,6 +295,9 @@ private HostConfig buildHostConfig() {
if (shmSize != null) {
config.withShmSize(shmSize);
}
if (tmpFsMapping != null) {
config.withTmpFs(tmpFsMapping);
}
return config;
}

Expand Down Expand Up @@ -1146,6 +1152,16 @@ public SELF withSharedMemorySize(Long bytes) {
return self();
}

/**
* First class support for configuring tmpfs
* @param mapping path and params of tmpfs/mount flag for container
* @return this
*/
public SELF withTmpFs(Map<String, String> mapping) {
this.tmpFsMapping = mapping;
return self();
}

/**
* Convenience class with access to non-public members of GenericContainer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.*;
import org.rnorth.ducttape.RetryCountExceededException;
import org.rnorth.ducttape.unreliables.Unreliables;
import org.testcontainers.containers.Container;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.Base58;
import org.testcontainers.utility.TestEnvironment;
Expand All @@ -26,6 +27,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.Collections.singletonMap;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.rnorth.visibleassertions.VisibleAssertions.*;
import static org.testcontainers.containers.BindMode.READ_ONLY;
Expand Down Expand Up @@ -158,6 +160,27 @@ public void testIsRunning() {
}
}

@Test
public void withTmpFsTest() throws Exception {
try (
GenericContainer container = new GenericContainer()
.withCommand("top")
.withTmpFs(singletonMap("/testtmpfs", "rw"))
) {
container.start();
// check file doesn't exist
String path = "/testtmpfs/test.file";
Container.ExecResult execResult = container.execInContainer("ls", path);
assertEquals("tmpfs inside container works fine", execResult.getStderr(),
"ls: /testtmpfs/test.file: No such file or directory\n");
// touch && check file does exist
container.execInContainer("touch", path);
execResult = container.execInContainer("ls", path);
assertEquals("tmpfs inside container works fine", execResult.getStdout(), path + "\n");
}
}


@Test
public void simpleRabbitMqTest() throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
Expand Down

0 comments on commit ef7c516

Please sign in to comment.