simba/t/00_da.t

55 lines
1.5 KiB
Perl

#!/usr/bin/perl
use warnings;
use strict;
use Test::More 'no_plan';
BEGIN { use_ok( 'Simba::DA' ); }
my $da = Simba::DA->new();
ok($da, 'new DA');
my $list;
open(my $fh, '>', \$list);
select $fh;
$da->list('list', 't/root');
ok($list);
cmp_ok($list, '=~', qr{t/root .* t=d }, 'root is a directory');
cmp_ok($list, '=~', qr{t/root/test.txt .* t=f s=14 }, 'text file found');
cmp_ok($list, '=~', qr{t/root/test.bin .* t=f s=1024 }, 'binary file found');
my $result;
open($fh, '>', \$result);
select $fh;
$da->get('get', 't/root/test.txt');
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);
}
ok($header, 'header found');
cmp_ok($header, '=~', qr{t/root/test.txt .* t=f s=14 }, 'text file found');
ok($content, 'content found');
cmp_ok(length($content), '==', 14, 'text file is 14 bytes long');
ok($trailer, 'trailer found');
is($trailer, 'chk sha1 e3b9312f5f7afbe0bfff5c49ab5e9a160b2b04f4', 'trailer contains correct checksum');
open($fh, '>', \$result);
select $fh;
$da->get('get', 't/root/test.bin');
($header, $content, $trailer)
= $result =~ /\A ([^\n]*) \n (.*) \n ([^\n]*) \n \z/xs;
ok($header, 'header found');
cmp_ok($header, '=~', qr{t/root/test.bin .* t=f s=1024 }, 'binary file found');
ok($content, 'content found');
cmp_ok(length($content), '==', 1024, 'binary file is 1024 bytes long');
ok($trailer, 'trailer found');
is($trailer, 'chk sha1 97253f25fc3945cd6293e3dfad2a322041b14164', 'trailer contains correct checksum');