Add a regression test for udisks
This commit is contained in:
parent
59ea2d7ba5
commit
2f51ca9609
|
@ -60,6 +60,7 @@ in rec {
|
||||||
(all nixos.tests.openssh)
|
(all nixos.tests.openssh)
|
||||||
(all nixos.tests.printing)
|
(all nixos.tests.printing)
|
||||||
(all nixos.tests.proxy)
|
(all nixos.tests.proxy)
|
||||||
|
(all nixos.tests.udisks)
|
||||||
(all nixos.tests.xfce)
|
(all nixos.tests.xfce)
|
||||||
|
|
||||||
nixpkgs.tarball
|
nixpkgs.tarball
|
||||||
|
|
|
@ -38,6 +38,7 @@ with import ../lib/testing.nix { inherit system minimal; };
|
||||||
simple = makeTest (import ./simple.nix);
|
simple = makeTest (import ./simple.nix);
|
||||||
#subversion = makeTest (import ./subversion.nix);
|
#subversion = makeTest (import ./subversion.nix);
|
||||||
tomcat = makeTest (import ./tomcat.nix);
|
tomcat = makeTest (import ./tomcat.nix);
|
||||||
|
udisks = makeTest (import ./udisks.nix);
|
||||||
#trac = makeTest (import ./trac.nix);
|
#trac = makeTest (import ./trac.nix);
|
||||||
xfce = makeTest (import ./xfce.nix);
|
xfce = makeTest (import ./xfce.nix);
|
||||||
runInMachine.test = import ./run-in-machine.nix { inherit system; };
|
runInMachine.test = import ./run-in-machine.nix { inherit system; };
|
||||||
|
|
56
nixos/tests/udisks.nix
Normal file
56
nixos/tests/udisks.nix
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
stick = pkgs.fetchurl {
|
||||||
|
url = http://nixos.org/~eelco/nix/udisks-test.img.xz;
|
||||||
|
sha256 = "0was1xgjkjad91nipzclaz5biv3m4b2nk029ga6nk7iklwi19l8b";
|
||||||
|
};
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
machine =
|
||||||
|
{ config, pkgs, ... }:
|
||||||
|
{ services.udisks.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("udisks --enumerate | grep /org/freedesktop/UDisks/devices/vda");
|
||||||
|
$machine->fail("udisks --enumerate | grep /org/freedesktop/UDisks/devices/sda1");
|
||||||
|
|
||||||
|
# Attach a USB stick and wait for it to show up.
|
||||||
|
$machine->sendMonitorCommand("usb_add disk:$stick");
|
||||||
|
$machine->waitUntilSucceeds("udisks --enumerate | grep /org/freedesktop/UDisks/devices/sda1");
|
||||||
|
$machine->succeed("udisks --show-info /dev/sda1 | grep 'label:.*USBSTICK'");
|
||||||
|
|
||||||
|
# Mount the stick as a non-root user and do some stuff with it.
|
||||||
|
$machine->succeed("su - alice -c 'udisks --enumerate | grep /org/freedesktop/UDisks/devices/sda1'");
|
||||||
|
$machine->succeed("su - alice -c 'udisks --mount /dev/sda1'");
|
||||||
|
$machine->succeed("su - alice -c 'cat /media/USBSTICK/test.txt'") =~ /Hello World/;
|
||||||
|
$machine->succeed("su - alice -c 'echo foo > /media/USBSTICK/bar.txt'");
|
||||||
|
|
||||||
|
# Unmounting the stick should make the mountpoint disappear.
|
||||||
|
$machine->succeed("su - alice -c 'udisks --unmount /dev/sda1'");
|
||||||
|
$machine->fail("[ -d /media/USBSTICK ]");
|
||||||
|
|
||||||
|
# Remove the USB stick.
|
||||||
|
$machine->sendMonitorCommand("usb_del 0.3"); # FIXME
|
||||||
|
$machine->waitUntilFails("udisks --enumerate | grep /org/freedesktop/UDisks/devices/sda1");
|
||||||
|
$machine->fail("[ -e /dev/sda ]");
|
||||||
|
'';
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue