X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F04multipart.t;h=074ca1068f8e9b2bf5e2687530d15c5444cea81c;hb=08160cca69ee960a312c88410dd5c5b3b376a577;hp=5e5726132b49ee2367d22226807f97bdaab8e425;hpb=4f8ae3af480f22fc9c7d83361954f1ffacc0d193;p=catagits%2FHTTP-Body.git diff --git a/t/04multipart.t b/t/04multipart.t index 5e57261..074ca10 100644 --- a/t/04multipart.t +++ b/t/04multipart.t @@ -3,13 +3,17 @@ use strict; use warnings; -use Test::More tests => 102; +use FindBin; +use lib "$FindBin::Bin/lib"; + +use Test::More tests => 153; +use Test::Deep; use Cwd; use HTTP::Body; use File::Spec::Functions; use IO::File; -use YAML; +use PAML; use File::Temp qw/ tempdir /; my $path = catdir( getcwd(), 't', 'data', 'multipart' ); @@ -17,8 +21,8 @@ my $path = catdir( getcwd(), 't', 'data', 'multipart' ); for ( my $i = 1; $i <= 13; $i++ ) { my $test = sprintf( "%.3d", $i ); - my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) ); - my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) ); + my $headers = PAML::LoadFile( catfile( $path, "$test-headers.pml" ) ); + my $results = PAML::LoadFile( catfile( $path, "$test-results.pml" ) ); my $content = IO::File->new( catfile( $path, "$test-content.dat" ) ); my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} ); my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() ); @@ -32,6 +36,11 @@ for ( my $i = 1; $i <= 13; $i++ ) { $body->add($buffer); } + # Tests >= 10 use auto-cleanup + if ( $i >= 10 ) { + $body->cleanup(1); + } + # Save tempnames for later deletion my @temps; @@ -41,17 +50,38 @@ for ( my $i = 1; $i <= 13; $i++ ) { for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) { like($_->{tempname}, qr{$regex_tempdir}, "has tmpdir $tempdir"); - push @temps, delete $_->{tempname}; + push @temps, $_->{tempname}; + } + + # Tell Test::Deep to ignore tempname values + if ( ref $value eq 'ARRAY' ) { + for ( @{ $results->{upload}->{$field} } ) { + $_->{tempname} = ignore(); + } + } + else { + $results->{upload}->{$field}->{tempname} = ignore(); } } - - is_deeply( $body->body, $results->{body}, "$test MultiPart body" ); - is_deeply( $body->param, $results->{param}, "$test MultiPart param" ); - is_deeply( $body->upload, $results->{upload}, "$test MultiPart upload" ) + + cmp_deeply( $body->body, $results->{body}, "$test MultiPart body" ); + cmp_deeply( $body->param, $results->{param}, "$test MultiPart param" ); + cmp_deeply( $body->param_order, $results->{param_order} ? $results->{param_order} : [], "$test MultiPart param_order" ); + cmp_deeply( $body->upload, $results->{upload}, "$test MultiPart upload" ) if $results->{upload}; cmp_ok( $body->state, 'eq', 'done', "$test MultiPart state" ); cmp_ok( $body->length, '==', $body->content_length, "$test MultiPart length" ); - # Clean up temp files created - unlink map { $_ } grep { -e $_ } @temps; -} + if ( $i < 10 ) { + # Clean up temp files created + unlink map { $_ } grep { -e $_ } @temps; + } + + undef $body; + + # Ensure temp files were deleted + for my $temp ( @temps ) { + ok( !-e $temp, "Temp file $temp was deleted" ); + } + +}