Skip to content
Open
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 @@ -153,9 +153,10 @@ private Map<String, String> parseTmpfsOptions(Map<String, String> containerParam

String tmpfsOptions = containerParameters.get("TC_TMPFS");

// Mount options are comma-separated too (e.g. "rw,size=64m"), so only split before a new "path:" entry
return Stream
.of(tmpfsOptions.split(","))
.collect(Collectors.toMap(string -> string.split(":")[0], string -> string.split(":")[1]));
.of(tmpfsOptions.split(",(?=[^,:]+:)"))
.collect(Collectors.toMap(string -> string.split(":", 2)[0], string -> string.split(":", 2)[1]));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;

class ConnectionUrlTest {

Expand Down Expand Up @@ -64,6 +65,23 @@ void testTmpfsOption() {
assertThat(url.getTmpfsOptions()).as("tmpfs option key1 has correct value").containsEntry("key1", "value1");
}

@Test
void testTmpfsOptionWithMultipleMountOptions() {
String urlString =
"jdbc:tc:postgresql:16://hostname/databasename?TC_TMPFS=/var/lib/postgresql/data:rw,size=256m,mode=1777";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);

assertThat(url.getTmpfsOptions()).containsOnly(entry("/var/lib/postgresql/data", "rw,size=256m,mode=1777"));
}

@Test
void testTmpfsOptionWithMultiplePathsAndMountOptions() {
String urlString = "jdbc:tc:postgresql:16://hostname/databasename?TC_TMPFS=/a:rw,size=64m,/b:ro";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);

assertThat(url.getTmpfsOptions()).containsOnly(entry("/a", "rw,size=64m"), entry("/b", "ro"));
}

@Test
void testInitScriptPathCapture() {
String urlString =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ void testDatabaseHasTmpFsViaConnectionString() throws Exception {
assertThat(execResult.getExitCode()).as("tmpfs inside container has file that does exist").isZero();
}
}

@Test
void testDatabaseHasTmpFsWithMountOptionsViaConnectionString() throws Exception {
final String jdbcUrl = "jdbc:tc:postgresql:9.6.8://hostname/databasename?TC_TMPFS=/testtmpfs:rw,size=64m";
try (Connection ignored = DriverManager.getConnection(jdbcUrl)) {
JdbcDatabaseContainer<?> container = ContainerDatabaseDriver.getContainer(jdbcUrl);
Container.ExecResult execResult = container.execInContainer("grep", "/testtmpfs", "/proc/mounts");
assertThat(execResult.getStdout()).as("tmpfs is mounted with the size option").contains("size=65536k");
}
}
}