From e48cce07fbc0fd7733244a8994a4530ff55f7c92 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 30 Apr 2007 03:55:05 +0000 Subject: [PATCH] 8 more tests for Storage.t for tar and untar. Reindented untar according to WGBP. Changed getFileContentsAsScalar to slurp the whole file at once. --- lib/WebGUI/Storage.pm | 19 +++++++++---------- t/Storage.t | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/lib/WebGUI/Storage.pm b/lib/WebGUI/Storage.pm index 34886c24a..a8d2ab344 100644 --- a/lib/WebGUI/Storage.pm +++ b/lib/WebGUI/Storage.pm @@ -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; } diff --git a/t/Storage.t b/t/Storage.t index 919d201f2..e0fba7492 100644 --- a/t/Storage.t +++ b/t/Storage.t @@ -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; } }