Skip to content

Commit

Permalink
Fix Java tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Apr 15, 2024
1 parent 222520b commit a9fe8a9
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
import java.io.IOException;
import java.time.Duration;
import java.util.regex.Pattern;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -180,7 +181,10 @@ public void hermeticTmp_tmpCreatedAndMounted() throws Exception {
assertThat(sandboxedSpawn).isInstanceOf(SymlinkedSandboxedSpawn.class);
String args = String.join(" ", sandboxedSpawn.getArguments());
assertThat(args).contains("-w /tmp");
assertThat(args).contains("-M " + hermeticTmpPath + " -m /tmp");
assertThat(args)
.matches(
".* -F %1$s/[^ ]+ -f %1$s/[^ ]+ .*"
.formatted(Pattern.quote(hermeticTmpPath.getPathString())));
}

@Test
Expand All @@ -200,11 +204,12 @@ public void hermeticTmp_sandboxTmpfsOnTmp_tmpNotCreatedOrMounted() throws Except
String args = String.join(" ", sandboxedSpawn.getArguments());
assertThat(args).contains("-w /tmp");
assertThat(args).contains("-e /tmp");
assertThat(args).doesNotContain("-m /tmp");
assertThat(args).doesNotContain("-F ");
assertThat(args).doesNotContain("-f ");
}

@Test
public void hermeticTmp_sandboxTmpfsUnderTmp_tmpNotCreatedOrMounted() throws Exception {
public void hermeticTmp_sandboxTmpfsUnderTmp_tmpCreatedAndMounted() throws Exception {
runtimeWrapper.addOptions(
"--incompatible_sandbox_hermetic_tmp", "--sandbox_tmpfs_path=/tmp/subdir");
CommandEnvironment commandEnvironment = createCommandEnvironment();
Expand All @@ -215,13 +220,15 @@ public void hermeticTmp_sandboxTmpfsUnderTmp_tmpNotCreatedOrMounted() throws Exc
Path sandboxPath =
sandboxedSpawn.getSandboxExecRoot().getParentDirectory().getParentDirectory();
Path hermeticTmpPath = sandboxPath.getRelative("_hermetic_tmp");
assertThat(hermeticTmpPath.isDirectory()).isFalse();
assertThat(hermeticTmpPath.isDirectory()).isTrue();

assertThat(sandboxedSpawn).isInstanceOf(SymlinkedSandboxedSpawn.class);
String args = String.join(" ", sandboxedSpawn.getArguments());
assertThat(args).contains("-w /tmp");
assertThat(args).contains("-e /tmp");
assertThat(args).doesNotContain("-m /tmp");
assertThat(args)
.matches(
".* -F %1$s/[^ ]+ -f %1$s/[^ ]+ .*"
.formatted(Pattern.quote(hermeticTmpPath.getPathString())));
}

private static LinuxSandboxedSpawnRunner setupSandboxAndCreateRunner(
Expand Down

0 comments on commit a9fe8a9

Please sign in to comment.