8 more tests for Storage.t for tar and untar.

Reindented untar according to WGBP.
Changed getFileContentsAsScalar to slurp the whole file at once.
This commit is contained in:
Colin Kuskie 2007-04-30 03:55:05 +00:00
parent 8b7bafe1ae
commit e48cce07fb
2 changed files with 40 additions and 12 deletions

View file

@ -518,9 +518,8 @@ sub getFileContentsAsScalar {
my $filename = shift;
my $content;
open (my $FILE,"<",$self->getPath($filename));
while (<$FILE>) {
$content .= $_;
}
local undef $/;
$content = <$FILE>;
close($FILE);
return $content;
}
@ -820,13 +819,13 @@ Pass in a storage location object to extract the contents to, instead of having
=cut
sub untar {
my $self = shift;
my $filename = shift;
my $temp = shift || WebGUI::Storage->createTemp($self->session);
chdir $temp->getPath;
Archive::Tar->extract_archive($self->getPath($filename),1);
$self->_addError(Archive::Tar->error) if (Archive::Tar->error);
return $temp;
my $self = shift;
my $filename = shift;
my $temp = shift || WebGUI::Storage->createTemp($self->session);
chdir $temp->getPath;
Archive::Tar->extract_archive($self->getPath($filename),1);
$self->_addError(Archive::Tar->error) if (Archive::Tar->error);
return $temp;
}

View file

@ -49,7 +49,7 @@ my $extensionTests = [
},
];
plan tests => 44 + scalar @{ $extensionTests }; # increment this value for each test you create
plan tests => 52 + scalar @{ $extensionTests }; # increment this value for each test you create
my $session = WebGUI::Test->session;
@ -272,8 +272,37 @@ isa_ok( $tempStor, "WebGUI::Storage", "createTemp creates WebGUI::Storage object
is ($tempStor->{_part1}, 'temp', 'createTemp puts stuff in the temp directory');
ok (-e $tempStor->getPath(), 'createTemp: directory was created');
####################################################
#
# tar
#
####################################################
my $tarStorage = $copiedStorage->tar('tar.tar');
isa_ok( $tarStorage, "WebGUI::Storage", "tar: returns a WebGUI::Storage object");
is ($tarStorage->{_part1}, 'temp', 'tar: puts stuff in the temp directory');
cmp_bag($tarStorage->getFiles(), [ 'tar.tar' ], 'tar: storage contains only the tar file');
isnt($tarStorage->getPath, $copiedStorage->getPath, 'tar did not reuse the same path as the source storage object');
####################################################
#
# untar
#
####################################################
my $untarStorage = $tarStorage->untar('tar.tar');
isa_ok( $untarStorage, "WebGUI::Storage", "untar: returns a WebGUI::Storage object");
is ($untarStorage->{_part1}, 'temp', 'untar: puts stuff in the temp directory');
##Note, getFiles will NOT recurse, so do not use a deep directory structure here
cmp_bag($untarStorage->getFiles, $copiedStorage->getFiles, 'tar and untar loop preserve all files');
isnt($untarStorage->getPath, $tarStorage->getPath, 'untar did not reuse the same path as the tar storage object');
END {
foreach my $stor ($storage1, $storage2, $storage3, $copiedStorage, $secondCopy, $s3copy, $tempStor) {
foreach my $stor (
$storage1, $storage2, $storage3, $copiedStorage,
$secondCopy, $s3copy, $tempStor, $tarStorage,
$untarStorage,
) {
ref $stor eq "WebGUI::Storage" and $stor->delete;
}
}