diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-04-19 14:37:05 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-04-19 14:37:05 +0200 |
commit | 894e2dfb258bfefb4080c89f94ac6cf253174ec6 (patch) | |
tree | ee0165fed2ab230dfd3e932993a431afaf88c528 | |
parent | fa9ed04997cc07d0782b79ec1929af2ac24e0045 (diff) |
Add a test for udisks2
-rw-r--r-- | nixos/release-combined.nix | 1 | ||||
-rw-r--r-- | nixos/release.nix | 1 | ||||
-rw-r--r-- | nixos/tests/udisks2.nix | 56 |
3 files changed, 58 insertions, 0 deletions
diff --git a/nixos/release-combined.nix b/nixos/release-combined.nix index 741ab62bbc03..32f523750004 100644 --- a/nixos/release-combined.nix +++ b/nixos/release-combined.nix @@ -61,6 +61,7 @@ in rec { (all nixos.tests.printing) (all nixos.tests.proxy) (all nixos.tests.udisks) + (all nixos.tests.udisks2) (all nixos.tests.xfce) nixpkgs.tarball diff --git a/nixos/release.nix b/nixos/release.nix index 45c37570c1ba..4a10ff39ed0c 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -245,6 +245,7 @@ in rec { tests.simple = callTest tests/simple.nix {}; tests.tomcat = callTest tests/tomcat.nix {}; tests.udisks = callTest tests/udisks.nix {}; + tests.udisks2 = callTest tests/udisks2.nix {}; tests.xfce = callTest tests/xfce.nix {}; } diff --git a/nixos/tests/udisks2.nix b/nixos/tests/udisks2.nix new file mode 100644 index 000000000000..e0c57d7c34d6 --- /dev/null +++ b/nixos/tests/udisks2.nix @@ -0,0 +1,56 @@ +import ./make-test.nix ({ pkgs, ... }: + +let + + stick = pkgs.fetchurl { + url = http://nixos.org/~eelco/nix/udisks-test.img.xz; + sha256 = "0was1xgjkjad91nipzclaz5biv3m4b2nk029ga6nk7iklwi19l8b"; + }; + +in + +{ + + machine = + { config, pkgs, ... }: + { services.udisks2.enable = true; + imports = [ ./common/user-account.nix ]; + + security.polkit.extraConfig = + '' + polkit.addRule(function(action, subject) { + if (subject.user == "alice") return "yes"; + }); + ''; + }; + + testScript = + '' + my $stick = $machine->stateDir . "/usbstick.img"; + system("xz -d < ${stick} > $stick") == 0 or die; + + $machine->succeed("udisksctl info -b /dev/vda >&2"); + $machine->fail("udisksctl info -b /dev/sda1"); + + # Attach a USB stick and wait for it to show up. + $machine->sendMonitorCommand("usb_add disk:$stick"); + $machine->waitUntilSucceeds("udisksctl info -b /dev/sda1"); + $machine->succeed("udisksctl info -b /dev/sda1 | grep 'IdLabel:.*USBSTICK'"); + + # Mount the stick as a non-root user and do some stuff with it. + $machine->succeed("su - alice -c 'udisksctl info -b /dev/sda1'"); + $machine->succeed("su - alice -c 'udisksctl mount -b /dev/sda1'"); + $machine->succeed("su - alice -c 'cat /run/media/alice/USBSTICK/test.txt'") =~ /Hello World/ or die; + $machine->succeed("su - alice -c 'echo foo > /run/media/alice/USBSTICK/bar.txt'"); + + # Unmounting the stick should make the mountpoint disappear. + $machine->succeed("su - alice -c 'udisksctl unmount -b /dev/sda1'"); + $machine->fail("[ -d /run/media/alice/USBSTICK ]"); + + # Remove the USB stick. + $machine->sendMonitorCommand("usb_del 0.3"); # FIXME + $machine->waitUntilFails("udisksctl info -b /dev/sda1"); + $machine->fail("[ -e /dev/sda ]"); + ''; + +}) |