Browse Source

- added notes

- added tests with empty payload file
tags/v0.067
Andreas Romeyke 1 month ago
parent
commit
385b29cabd
1 changed files with 40 additions and 5 deletions
  1. +40
    -5
      t/store_bag.t

+ 40
- 5
t/store_bag.t View File

@@ -4,7 +4,7 @@ BEGIN { chdir 't' if -d 't' }
use warnings;
use utf8;
use open ':std', ':encoding(UTF-8)';
use Test::More tests => 56;
use Test::More tests => 71;
use Test::File;
use Test::Warnings;
use strict;
@@ -22,10 +22,11 @@ use File::Slurp qw( read_file write_file);
my $special = '#--Ä--ä--Ö--ö--Ü--ü--ß--.[{!}].--$';
my $special_re = qr|#--Ä--ä--Ö--ö--Ü--ü--ß--\.\[\{!\}\]\.--\$|;

use_ok('Archive::BagIt::Base');

{
note("simple bag");
my $dir = tempdir(CLEANUP => 1);

use_ok('Archive::BagIt::Base');
mkdir(File::Spec->catdir($dir, "data"));
write_file(File::Spec->catfile($dir, "data", "1.txt"), "1");
ok(Archive::BagIt::Base->make_bag($dir), "make_bag()");
@@ -45,8 +46,8 @@ my $special_re = qr|#--Ä--ä--Ö--ö--Ü--ü--ß--\.\[\{!\}\]\.--\$|;
}

{
note ("bag with special filenames");
my $dir = tempdir(CLEANUP => 1);
use_ok('Archive::BagIt::Base');
mkdir(File::Spec->catdir($dir, "data"));
my $subdir = File::Spec->catdir($dir, "data", $special);
mkdir($subdir);
@@ -87,8 +88,8 @@ my $special_re = qr|#--Ä--ä--Ö--ö--Ü--ü--ß--\.\[\{!\}\]\.--\$|;
file_contains_utf8_like(File::Spec->catfile($dir, "bag-info.txt"), qr{^Bag-Size: 2 B$}m);
}
{
note ("bag with meta/ dir");
my $dir = tempdir(CLEANUP => 1);
use_ok('Archive::BagIt::Base');
mkdir(File::Spec->catdir($dir, "data"));
my $subdir = File::Spec->catdir($dir, "data", $special);
mkdir($subdir);
@@ -118,4 +119,38 @@ my $special_re = qr|#--Ä--ä--Ö--ö--Ü--ü--ß--\.\[\{!\}\]\.--\$|;
file_contains_utf8_like(File::Spec->catfile($dir, "bag-info.txt"), qr{^Bag-Size: 2 B$}m);
}

{ # bag with 0-byte files
note ("bag with empty payload file");
my $dir = tempdir(CLEANUP => 1);
mkdir(File::Spec->catdir($dir, "data"));
write_file(File::Spec->catfile($dir, "data", "1.txt"), '');
my $bag;
my $warning = Test::Warnings::warning { $bag = Archive::BagIt::Base->make_bag($dir) };
like (
$warning->[0] ,
qr/empty file .* detected/,
'Got expected warning from make_bag()',
) or diag 'got unexpected warnings:' , explain($warning);
like (
$warning->[1] ,
qr/empty file .* detected/,
'Got expected warning from make_bag()',
) or diag 'got unexpected warnings:' , explain($warning);
ok ($bag, "Object created");
isa_ok ($bag, 'Archive::BagIt::Base');
file_exists_ok(File::Spec->catfile($dir, "bag-info.txt"));
file_exists_ok(File::Spec->catfile($dir, "bagit.txt"));
file_exists_ok(File::Spec->catfile($dir, "data", "1.txt"));
file_exists_ok(File::Spec->catfile($dir, "manifest-md5.txt"));
file_exists_ok(File::Spec->catfile($dir, "tagmanifest-md5.txt"));
file_exists_ok(File::Spec->catfile($dir, "manifest-sha512.txt"));
file_exists_ok(File::Spec->catfile($dir, "tagmanifest-sha512.txt"));
file_contains_utf8_like(File::Spec->catfile($dir, "bagit.txt"), qr{^BagIt-Version: 1.0$}m);
file_contains_utf8_like(File::Spec->catfile($dir, "bagit.txt"), qr{^Tag-File-Character-Encoding: UTF-8$}m);
file_contains_utf8_like(File::Spec->catfile($dir, "bag-info.txt"), qr{^Bagging-Date: \d\d\d\d-\d\d-\d\d$}m);
file_contains_utf8_like(File::Spec->catfile($dir, "bag-info.txt"), qr{^Bag-Software-Agent: Archive::BagIt}m);
file_contains_utf8_like(File::Spec->catfile($dir, "bag-info.txt"), qr{^Payload-Oxum: 0\.1$}m);
file_contains_utf8_like(File::Spec->catfile($dir, "bag-info.txt"), qr{^Bag-Size: 0 B$}m);
}

1;

Loading…
Cancel
Save