aboutsummaryrefslogtreecommitdiffstats
path: root/t/22-eject.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/22-eject.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/22-eject.t')
-rw-r--r--t/22-eject.t41
1 files changed, 41 insertions, 0 deletions
diff --git a/t/22-eject.t b/t/22-eject.t
new file mode 100644
index 0000000..50511f1
--- /dev/null
+++ b/t/22-eject.t
@@ -0,0 +1,41 @@
+use strict;
+use lib 't';
+use helper;
+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');
+
+my $fake_device = create_fake_media();
+
+my $cdroms = Hal::Cdroms->new;
+
+my @udisks_paths = grep { $_ eq "/org/freedesktop/UDisks2/block_devices/$fake_device" } $cdroms->list;
+ok(@udisks_paths == 1, 'device is listed');
+
+# If a volume manager is running, the device may get auto-mounted.
+# Allow this to settle before proceeding.
+sleep(2);
+
+# Ensure the device is mounted.
+ok($cdroms->ensure_mounted($udisks_paths[0]), 'ensure_mounted returns success');
+my $mount_point = find_mount_point($fake_device);
+ok($mount_point, 'device is mounted');
+
+# Test that we can eject it.
+ok($cdroms->eject($udisks_paths[0]), 'eject returns success');
+$mount_point = find_mount_point($fake_device);
+ok(!$mount_point, 'device is unmounted');
+ok(!$cdroms->get_mount_point($udisks_paths[0]), 'get_mount_point returns no path');
+
+# It appears the scsi_debug module doesn't support eject, so we have to skip this.
+# ok(! -e "/dev/$fake_device", 'device has been ejected');
+
+ok(!$cdroms->eject($udisks_paths[0]), 'repeated eject fails');
+
+done_testing();
+
+END {
+ remove_fake_media() if $> == 0;
+}