X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F11new-suffix.t;fp=t%2F11new-suffix.t;h=42c8ffed515eabea1d9b13c3b8049d136355bda3;hb=cc75c886256f187cda388641931e8dafad6c2346;hp=0000000000000000000000000000000000000000;hpb=b554d2f5fac821338a7508f412f658015cd1e0bd;p=catagits%2FHTTP-Body.git diff --git a/t/11new-suffix.t b/t/11new-suffix.t new file mode 100644 index 0000000..42c8ffe --- /dev/null +++ b/t/11new-suffix.t @@ -0,0 +1,99 @@ +#!perl + +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/lib"; + +use Test::More tests => 6; +use Test::Deep; + +use Cwd; +use HTTP::Body; +use File::Spec::Functions; +use IO::File; +use PAML; +use File::Temp qw/ tempdir /; + +my $path = catdir( getcwd(), 't', 'data', 'multipart' ); + +{ + my $uploads = uploads_for('001'); + + { + my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload2}{tempname} ); + like( + $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/, + 'everything is file_temp_suffix now' + ); + } + + { + my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload4}{tempname} ); + like( + $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/, + 'everything is file_temp_suffix now' + ); + } + +} + +{ + my $uploads = uploads_for('006'); + + { + my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload2}{tempname} ); + like( + $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/, + 'everything is file_temp_suffix now' + ); + } + +} + +{ + my $uploads = uploads_for('014'); + + { + my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload}{tempname} ); + like( + $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/, + 'everything is file_temp_suffix now' + ); + } + + { + my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload2}{tempname} ); + like( + $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/, + 'everything is file_temp_suffix now' + ); + } + + like( + $uploads->{upload2}{tempname}, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/, + 'everything is file_temp_suffix now' + ); + +} + +sub uploads_for { + my $number = shift; + + my $headers = PAML::LoadFile( catfile( $path, "$number-headers.pml" ) ); + my $content = IO::File->new( catfile( $path, "$number-content.dat" ) ); + my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} ); + my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() ); + $body->tmpdir($tempdir); + + binmode $content, ':raw'; + + while ( $content->read( my $buffer, 1024 ) ) { + $body->add($buffer); + } + + $body->cleanup(1); + + return $body->upload; +}