2006-10-02 14:18:30 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2007-02-10 23:05:25 +01:00
|
|
|
use Test::More tests => 22;
|
2006-10-02 14:18:30 +02:00
|
|
|
|
|
|
|
BEGIN { use_ok( 'Simba::DA' ); }
|
|
|
|
|
|
|
|
my $da = Simba::DA->new();
|
|
|
|
ok($da, 'new DA');
|
2006-11-20 16:06:39 +01:00
|
|
|
$da->log_level(0); # no log output during tests
|
2006-10-02 14:18:30 +02:00
|
|
|
my $list;
|
|
|
|
open(my $fh, '>', \$list);
|
2006-11-20 00:00:08 +01:00
|
|
|
$da->fh_out($fh);
|
2006-10-02 14:18:30 +02:00
|
|
|
$da->list('list', 't/root');
|
2006-11-20 00:00:08 +01:00
|
|
|
close($fh);
|
2006-10-02 14:18:30 +02:00
|
|
|
ok($list);
|
2006-11-20 00:31:07 +01:00
|
|
|
cmp_ok($list, '=~', qr{^\. .* t=d }m, 'root is a directory');
|
|
|
|
cmp_ok($list, '=~', qr{^\./test.txt .* t=f s=14 }m, 'text file found');
|
|
|
|
cmp_ok($list, '=~', qr{^\./test.bin .* t=f s=1024 }m, 'binary file found');
|
2006-11-28 17:14:35 +01:00
|
|
|
cmp_ok($list, '=~', qr{^\./test.link .* t=l .* lt=test.bin( |$)}m, 'symlink found');
|
2007-02-10 23:05:25 +01:00
|
|
|
cmp_ok($list, '=~', qr{^\./ABAecom_=sub.__Am._Bankers_Assn.=_Root_CA.pem .* t=l .* lt=/usr/share/ca-certificates/mozilla/ABAecom_=sub.__Am._Bankers_Assn.=_Root_CA.crt( |$)}m, 'symlink found');
|
2006-10-02 14:18:30 +02:00
|
|
|
|
2006-10-02 16:33:26 +02:00
|
|
|
my $result;
|
|
|
|
open($fh, '>', \$result);
|
2006-11-20 00:00:08 +01:00
|
|
|
$da->fh_out($fh);
|
2006-11-20 00:31:07 +01:00
|
|
|
$da->get('get', './test.txt');
|
2006-10-02 16:33:26 +02:00
|
|
|
ok($result, 'get returned something');
|
|
|
|
|
|
|
|
my ($header, $content, $trailer);
|
|
|
|
if ($result =~ /\A ([^\n]*) \n (.*) \n ([^\n]*) \n \z/xs) {
|
|
|
|
($header, $content, $trailer) = ($1, $2, $3);
|
|
|
|
}
|
2006-10-02 14:18:30 +02:00
|
|
|
|
|
|
|
ok($header, 'header found');
|
2006-11-20 00:31:07 +01:00
|
|
|
cmp_ok($header, '=~', qr{./test.txt .* t=f s=14 }, 'text file found');
|
2006-10-02 14:18:30 +02:00
|
|
|
|
|
|
|
ok($content, 'content found');
|
2006-10-02 16:33:26 +02:00
|
|
|
cmp_ok(length($content), '==', 14, 'text file is 14 bytes long');
|
2006-10-02 14:18:30 +02:00
|
|
|
|
|
|
|
ok($trailer, 'trailer found');
|
|
|
|
is($trailer, 'chk sha1 e3b9312f5f7afbe0bfff5c49ab5e9a160b2b04f4', 'trailer contains correct checksum');
|
|
|
|
|
2006-10-02 16:33:26 +02:00
|
|
|
open($fh, '>', \$result);
|
2006-11-20 00:00:08 +01:00
|
|
|
$da->fh_out($fh);
|
2006-11-20 00:31:07 +01:00
|
|
|
$da->get('get', './test.bin');
|
2006-10-02 16:33:26 +02:00
|
|
|
|
2006-10-02 14:18:30 +02:00
|
|
|
($header, $content, $trailer)
|
2006-10-02 16:33:26 +02:00
|
|
|
= $result =~ /\A ([^\n]*) \n (.*) \n ([^\n]*) \n \z/xs;
|
2006-10-02 14:18:30 +02:00
|
|
|
|
|
|
|
ok($header, 'header found');
|
2006-11-20 00:31:07 +01:00
|
|
|
cmp_ok($header, '=~', qr{./test.bin .* t=f s=1024 }, 'binary file found');
|
2006-10-02 14:18:30 +02:00
|
|
|
|
|
|
|
ok($content, 'content found');
|
2006-11-20 00:31:07 +01:00
|
|
|
|
2006-10-02 16:33:26 +02:00
|
|
|
cmp_ok(length($content), '==', 1024, 'binary file is 1024 bytes long');
|
2006-10-02 14:18:30 +02:00
|
|
|
|
|
|
|
ok($trailer, 'trailer found');
|
|
|
|
is($trailer, 'chk sha1 97253f25fc3945cd6293e3dfad2a322041b14164', 'trailer contains correct checksum');
|
2006-11-20 00:00:08 +01:00
|
|
|
|
|
|
|
open($fh, '>', \$result);
|
|
|
|
$da->fh_out($fh);
|
|
|
|
$da->no_such_command('no_such_command');
|
|
|
|
cmp_ok(length($result), '>', 0, 'invoking nonexistant command produces message');
|
|
|
|
|