2007-11-17 22:03:10 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
# Live tests.
|
|
|
|
#
|
|
|
|
# These tests need to be run as simba_ca and it needs to be able to
|
|
|
|
# connect to simba_da@localhost.
|
|
|
|
|
|
|
|
use Test::More tests => 8;
|
|
|
|
|
|
|
|
use File::stat;
|
|
|
|
|
|
|
|
BEGIN { use_ok( 'Simba::CA' ); }
|
|
|
|
|
|
|
|
my $ca = Simba::CA->new({ dbi_file => $ENV{SIMBA_DB_CONN} ||
|
|
|
|
"$ENV{HOME}/.dbi/simba_test"});
|
|
|
|
|
|
|
|
ok($ca, 'new CA');
|
|
|
|
|
|
|
|
# make sure filesets contains test data then connect again:
|
|
|
|
$ca->{dbh}->do("delete from filesets");
|
|
|
|
$ca->{dbh}->do("insert into filesets(host, dir) values('localhost', '/var/tmp/simba_test')");
|
|
|
|
|
|
|
|
$ca = Simba::CA->new({ dbi_file => $ENV{SIMBA_DB_CONN} ||
|
|
|
|
"$ENV{HOME}/.dbi/simba_test"});
|
|
|
|
|
|
|
|
ok($ca, 'new CA 2');
|
|
|
|
|
|
|
|
|
|
|
|
SKIP: {
|
2008-04-05 13:21:51 +02:00
|
|
|
skip "not running as root", 5 unless $> == 0;
|
2007-11-17 22:03:10 +01:00
|
|
|
mkdir "/var/tmp/simba_test";
|
|
|
|
mkdir "/var/tmp/simba_test/d1";
|
|
|
|
mkdir "/var/tmp/simba_test/d2";
|
|
|
|
|
|
|
|
open my $fh, '>:raw', '/var/tmp/simba_test/d1/f1';
|
|
|
|
print $fh "test\n";
|
|
|
|
close($fh);
|
|
|
|
|
|
|
|
open $fh, '>:raw', '/var/tmp/simba_test/d2/f2';
|
|
|
|
print $fh "test\n";
|
|
|
|
close($fh);
|
|
|
|
|
2009-06-28 22:24:18 +02:00
|
|
|
open $fh, '>:raw', '/var/tmp/simba_test/d2/f3';
|
|
|
|
print $fh "#!/bin/sh\n";
|
|
|
|
chmod(04511, $fh);
|
|
|
|
close($fh);
|
|
|
|
|
2007-11-17 22:03:10 +01:00
|
|
|
$ca->run();
|
|
|
|
my $this_backup = $ca->{this_backup};
|
2009-06-28 22:24:18 +02:00
|
|
|
|
2007-11-17 22:03:10 +01:00
|
|
|
my $st1 = lstat("$this_backup/d1/f1");
|
|
|
|
ok($st1, "file 1 exists");
|
|
|
|
is($st1->nlink, 2, "file 1 has 2 links");
|
2009-06-28 22:24:18 +02:00
|
|
|
|
2007-11-17 22:03:10 +01:00
|
|
|
my $st2 = lstat("$this_backup/d2/f2");
|
|
|
|
ok($st2, "file 2 exists");
|
|
|
|
is($st2->nlink, 2, "file 2 has 2 links");
|
|
|
|
is($st1->ino, $st2->ino, , "file 1 and 2 are the same");
|
|
|
|
|
2009-06-28 22:24:18 +02:00
|
|
|
my $st3 = lstat("$this_backup/d2/f3");
|
|
|
|
ok($st3, "file 3 exists");
|
|
|
|
cmp_ok($st3->mode & 07777, '==', 04511, , "mode of file 3 is correct");
|
|
|
|
|
2007-11-17 22:03:10 +01:00
|
|
|
# cleanup
|
|
|
|
system("rm", "-rf", $this_backup);
|
|
|
|
$ca->{dbh}->do("delete from versions");
|
|
|
|
$ca->{dbh}->do("delete from files");
|
|
|
|
$ca->{dbh}->do("delete from filesets");
|
|
|
|
|
|
|
|
}
|