about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2017-11-21 07:42:53 +0100
committeraszlig <aszlig@nix.build>2017-11-21 07:44:57 +0100
commitda3aa9a273544efc8d13864439cf73c35d30855c (patch)
tree8e532b118c6e996f27646d7605bb9e3b5f2a43e3 /tests
parent57df162fb098f0362a9b3f9e8cf497a5217cfab3 (diff)
tests: Add simple test for buildSandbox
This is only a very rudimentary test of the sandbox implementation, but
it already serves as a series of regression test for a few problems I
ran into so far.

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'tests')
-rw-r--r--tests/default.nix1
-rw-r--r--tests/games/sandbox.nix42
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/default.nix b/tests/default.nix
index 31fa8154..0d03bc62 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -7,6 +7,7 @@ let
 
 in {
   games = {
+    sandbox = callTest ./games/sandbox.nix;
     starbound = callTest ./games/starbound.nix;
   };
   programs = {
diff --git a/tests/games/sandbox.nix b/tests/games/sandbox.nix
new file mode 100644
index 00000000..98d29870
--- /dev/null
+++ b/tests/games/sandbox.nix
@@ -0,0 +1,42 @@
+{
+  name = "sandbox";
+
+  machine = { pkgs, lib, ... }: {
+    nixpkgs.config.vuizvui.games = {};
+    system.activationScripts.inject-link = ''
+      ln -svf ${pkgs.hello} /run/foo-test-sandbox
+      ln -svf ${pkgs.gnused} /run/bar-test-sandbox
+      ln -svf ${pkgs.gnugrep} /run/baz-test-sandbox
+    '';
+    environment.sessionVariables.COLLECT_ME = [
+      "/run/foo-test-sandbox"
+      "/run/bar-test-sandbox"
+      "/run/baz-test-sandbox"
+    ];
+    environment.systemPackages = let
+      testProgram = pkgs.writeScriptBin "test-sandbox" ''
+        #!${pkgs.stdenv.shell} -ex
+        ! echo foo | grep -qF foo
+        export PATH=/run/baz-test-sandbox/bin
+        echo foo > /home/foo/existing/bar
+        test ! -d /home/foo/nonexisting
+        /run/foo-test-sandbox/bin/hello
+        echo aaa | /run/bar-test-sandbox/bin/sed -e 's/a/b/g'
+      '';
+    in lib.singleton (pkgs.vuizvui.games.buildSandbox testProgram {
+      paths.required = [ "/home/foo/existing" ];
+      paths.wanted = [ "/home/foo/nonexisting" ];
+      paths.runtimeVars = [ "COLLECT_ME" ];
+    });
+    users.users.foo.isNormalUser = true;
+  };
+
+  testScript = ''
+    $machine->waitForUnit('multi-user.target');
+    $machine->succeed('su - -c test-sandbox foo >&2');
+
+    $machine->succeed('test -d /home/foo/existing');
+    $machine->succeed('grep -qF foo /home/foo/existing/bar');
+    $machine->fail('test -d /home/foo/nonexisting');
+  '';
+}