source: MondoRescue/branches/3.2/MondoRescue/t/01-read-all-link.t @ 3228

Last change on this file since 3228 was 3228, checked in by Bruno Cornec, 7 years ago
  • Add a test file for MondoRescue::File for the mr_read_all_link function which is a critical one
  • Function now work as expected including normalization
  • Property svn:executable set to *
File size: 2.8 KB
Line 
1#!/usr/bin/perl -w
2use Test::More 'no_plan';
3use File::Temp qw/ tempdir /;
4use File::Copy;
5use MondoRescue::File;
6use strict;
7
8# Create the structure for the tests
9my $bd = tempdir(
10    CLEANUP => 1
11    );
12
13# Create directory structure
14chdir $bd || die "Unable to chdir to $bd";
15mkdir "usr",0755 || die "$!";
16mkdir "usr/bin",0755 || die "$!";
17mkdir "usr/lib",0755 || die "$!";
18mkdir "var",0755 || die "$!";
19mkdir "var/spool",0755 || die "$!";
20mkdir "var/spool/mail",0755 || die "$!";
21mkdir "var/lib",0755 || die "$!";
22
23# Copy some files in it
24copy "/usr/bin/perl","usr/bin" || die "$!";
25chmod 0755,"usr/bin/perl";
26my $libc;
27foreach my $f (<"/lib/libc.so.[0-9]*">) {
28    copy "$f","usr/lib" || die "$!";
29    $libc = $f;
30}
31
32# Create links on files
33chdir "$bd/usr/bin" || die "$!";
34symlink "perl","toto" || die "$!";          # in same dir
35chdir "$bd/var/spool/" || die "$!";
36symlink "../../usr/bin/perl","toto" || die "$!";    # in another dir relatively
37chdir "$bd/var" || die "$!";
38symlink "$bd/usr/bin/perl","truc" || die "$!";      # in another dir absolutely
39
40# Create links on dirs
41chdir "$bd/var/spool" || die "$!";
42symlink "mail","titi" || die "$!";          # in same dir
43chdir "$bd/var/lib" || die "$!";
44symlink "../spool/mail","titi" || die "$!";     # in another dir relatively
45chdir "$bd/var" || die "$!";
46symlink "$bd/var/spool/mail","tutu" || die "$!";        # in another dir absolutely
47
48print "Temporary dir: $bd\n";
49
50# Now try to see if we get the right links
51my $h = mr_file_read_all_link(
52    "$bd/usr/bin/toto",
53    "$bd/var/spool/toto",
54    "$bd/var/truc",
55    "$bd/var/spool/titi",
56    "$bd/var/lib/titi",
57    "$bd/var/tutu"
58    );
59
60    # Got, expected, comment
61is(@{$h->{"$bd/usr/bin/toto"}}[0], "$bd/usr/bin/toto", "File link in same dir to itself");
62is(@{$h->{"$bd/usr/bin/toto"}}[1], "$bd/usr/bin/perl", "File link in same dir to link");
63is(@{$h->{"$bd/var/truc"}}[0], "$bd/var/truc", "File link in another absolute dir to itself");
64is(@{$h->{"$bd/var/truc"}}[1], "$bd/usr/bin/perl", "File link in another absolute dir to link");
65is(@{$h->{"$bd/var/spool/toto"}}[0], "$bd/var/spool/toto", "File link in another relative dir to itself");
66is(@{$h->{"$bd/var/spool/toto"}}[1], "$bd/usr/bin/perl", "File link in another relative dir to link");
67is(@{$h->{"$bd/var/spool/titi"}}[0], "$bd/var/spool/titi", "Directory link in same dir to itself");
68is(@{$h->{"$bd/var/spool/titi"}}[1], "$bd/var/spool/mail", "Directory link in same dir to link");
69is(@{$h->{"$bd/var/lib/titi"}}[0], "$bd/var/lib/titi", "Directory link in another relative dir to itself");
70is(@{$h->{"$bd/var/lib/titi"}}[1], "$bd/var/spool/mail", "Directory link in another relative dir to link");
71is(@{$h->{"$bd/var/tutu"}}[0], "$bd/var/tutu", "Directory link in another absolute dir to itself");
72is(@{$h->{"$bd/var/tutu"}}[1], "$bd/var/spool/mail", "Directory link in another absolute dir to link");
73chdir "/tmp";
74exit(0);
Note: See TracBrowser for help on using the repository browser.