aboutsummaryrefslogtreecommitdiffstats
path: root/t/24-wait-for-mounted.t
diff options
context:
space:
mode:
authorMartin Whitaker <mageia@martin-whitaker.me.uk>2020-05-05 22:42:51 +0100
committerMartin Whitaker <mageia@martin-whitaker.me.uk>2020-05-05 22:42:51 +0100
commita08300033d2ccaa6f2704535f977fb876da93b65 (patch)
tree8ea73642300ba5ddb75c7b8eb61ba2bd3dbc9c9e /t/24-wait-for-mounted.t
parent2d28e08b9584e35e9b268f0ddde161e4b899bbd2 (diff)
downloadperl-Hal-Cdroms-a08300033d2ccaa6f2704535f977fb876da93b65.tar
perl-Hal-Cdroms-a08300033d2ccaa6f2704535f977fb876da93b65.tar.gz
perl-Hal-Cdroms-a08300033d2ccaa6f2704535f977fb876da93b65.tar.bz2
perl-Hal-Cdroms-a08300033d2ccaa6f2704535f977fb876da93b65.tar.xz
perl-Hal-Cdroms-a08300033d2ccaa6f2704535f977fb876da93b65.zip
Add functional tests.
Diffstat (limited to 't/24-wait-for-mounted.t')
-rw-r--r--t/24-wait-for-mounted.t41
1 files changed, 41 insertions, 0 deletions
diff --git a/t/24-wait-for-mounted.t b/t/24-wait-for-mounted.t
new file mode 100644
index 0000000..6695abe
--- /dev/null
+++ b/t/24-wait-for-mounted.t
@@ -0,0 +1,41 @@
+use strict;
+use lib 't';
+use helper;
+use File::Temp qw(tempdir);
+use Test::More;
+plan skip_all => "You need to be root to run this test" if $> != 0;
+plan skip_all => "The scsi_debug kernel module is needed to run this test" if !can_create_fake_media();
+
+use_ok('Hal::Cdroms');
+
+# Check if a volume manager is going to auto-mount the device.
+my $fake_device = create_fake_media();
+sleep(2);
+my $auto_mounted = 0;
+if (find_mount_point($fake_device)) {
+ system("umount /dev/$fake_device");
+ remove_fake_media();
+ $auto_mounted = 1;
+}
+
+my $fake_device = create_fake_media(3);
+
+if (!$auto_mounted) {
+ my $tmp_dir = tempdir(CLEANUP => 1);
+ system("echo 'sleep 4; mount /dev/$fake_device $tmp_dir' | at now >& /dev/null");
+}
+
+my $cdroms = Hal::Cdroms->new;
+
+my $udisks_path = $cdroms->wait_for_mounted();
+ok($udisks_path eq "/org/freedesktop/UDisks2/block_devices/$fake_device", 'wait_for_mounted returns correct path');
+my $mount_point = find_mount_point($fake_device);
+ok($mount_point, 'device is mounted');
+ok($cdroms->get_mount_point($udisks_path) eq $mount_point, 'get_mount_point returns correct path');
+
+done_testing();
+
+END {
+ system("umount /dev/$fake_device") if find_mount_point($fake_device);
+ remove_fake_media() if $> == 0;
+}