aboutsummaryrefslogtreecommitdiffstats
path: root/t/24-wait-for-mounted.t
blob: 72555b05d6f685867fad31cb80ff66e9a729fb10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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();
plan 'no_plan';

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("(sleep 4; mount /dev/$fake_device $tmp_dir)&");
}

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;
}