6 use Test::More tests => 140;
11 use File::Spec::Functions;
14 use File::Temp qw/ tempdir /;
16 my $path = catdir( getcwd(), 't', 'data', 'multipart' );
18 for ( my $i = 1; $i <= 13; $i++ ) {
20 my $test = sprintf( "%.3d", $i );
21 my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
22 my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) );
23 my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
24 my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
25 my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() );
26 $body->tmpdir($tempdir);
28 my $regex_tempdir = quotemeta($tempdir);
30 binmode $content, ':raw';
32 while ( $content->read( my $buffer, 1024 ) ) {
36 # Tests >= 10 use auto-cleanup
41 # Save tempnames for later deletion
44 for my $field ( keys %{ $body->upload } ) {
46 my $value = $body->upload->{$field};
48 for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) {
49 like($_->{tempname}, qr{$regex_tempdir}, "has tmpdir $tempdir");
50 push @temps, $_->{tempname};
53 # Tell Test::Deep to ignore tempname values
54 if ( ref $value eq 'ARRAY' ) {
55 for ( @{ $results->{upload}->{$field} } ) {
56 $_->{tempname} = ignore();
60 $results->{upload}->{$field}->{tempname} = ignore();
64 cmp_deeply( $body->body, $results->{body}, "$test MultiPart body" );
65 cmp_deeply( $body->param, $results->{param}, "$test MultiPart param" );
66 cmp_deeply( $body->upload, $results->{upload}, "$test MultiPart upload" )
67 if $results->{upload};
68 cmp_ok( $body->state, 'eq', 'done', "$test MultiPart state" );
69 cmp_ok( $body->length, '==', $body->content_length, "$test MultiPart length" );
72 # Clean up temp files created
73 unlink map { $_ } grep { -e $_ } @temps;
78 # Ensure temp files were deleted
79 for my $temp ( @temps ) {
80 ok( !-e $temp, "Temp file $temp was deleted" );