X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Faggregate%2Flive_engine_request_uploads.t;h=5ba8f1858cc238bc9bf0969b82f012acf6b162b6;hp=245433016281303db018e438eecece1d67c3c891;hb=efc1a69b1e03a40bc721aa745846d45f855b9511;hpb=42da66a91b0a87ebb81d8552bcd0b05d3557c83e diff --git a/t/aggregate/live_engine_request_uploads.t b/t/aggregate/live_engine_request_uploads.t index 2454330..5ba8f18 100644 --- a/t/aggregate/live_engine_request_uploads.t +++ b/t/aggregate/live_engine_request_uploads.t @@ -1,16 +1,15 @@ -#!perl - use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; -use Test::More tests => 88; +use Test::More tests => 105; use Catalyst::Test 'TestApp'; - +use Scalar::Util qw/ blessed /; use Catalyst::Request; use Catalyst::Request::Upload; +use HTTP::Body::OctetStream; use HTTP::Headers; use HTTP::Headers::Util 'split_header_words'; use HTTP::Request::Common; @@ -72,7 +71,13 @@ use Path::Class::Dir; is( $creq->parameters->{ $upload->filename }, $upload->filename, 'legacy param method ok' ); - ok( !-e $upload->tempname, 'Upload temp file was deleted' ); + SKIP: + { + if ( $ENV{CATALYST_SERVER} ) { + skip 'Not testing for deleted file on remote server', 1; + } + ok( !-e $upload->tempname, 'Upload temp file was deleted' ); + } } } @@ -127,8 +132,15 @@ use Path::Class::Dir; is( $upload->type, $part->content_type, 'Upload Content-Type' ); is( $upload->filename, $parameters{filename}, 'Upload filename' ); is( $upload->size, length( $part->content ), 'Upload Content-Length' ); - - ok( !-e $upload->tempname, 'Upload temp file was deleted' ); + is( $upload->basename, $parameters{filename}, 'Upload basename' ); + + SKIP: + { + if ( $ENV{CATALYST_SERVER} ) { + skip 'Not testing for deleted file on remote server', 1; + } + ok( !-e $upload->tempname, 'Upload temp file was deleted' ); + } } } @@ -146,6 +158,8 @@ use Path::Class::Dir; ok( $response->is_success, 'Response Successful 2xx' ); is( $response->content_type, 'text/plain', 'Response Content-Type' ); is( $response->content, ( $request->parts )[0]->content, 'Content' ); + + # XXX: no way to test that temporary file for this test was deleted } { @@ -181,8 +195,36 @@ use Path::Class::Dir; ok( my $response = request($request), 'Request' ); ok( $response->is_success, 'Response Successful 2xx' ); is( $response->content_type, 'text/plain', 'Response Content-Type' ); - like( $response->content, qr/file1 => bless/, 'Upload with name file1'); - like( $response->content, qr/file2 => bless/, 'Upload with name file2'); + { + local $@; + my $request = eval $response->content; + if ($@) { + fail("Could not inflate response: $@ " . $response->content); + } + else { + ok blessed($request->uploads->{file1}), 'Upload with name file1'; + ok blessed($request->uploads->{file2}),'Upload with name file2'; + } + } + my $creq; + { + no strict 'refs'; + ok( + eval '$creq = ' . $response->content, + 'Unserialize Catalyst::Request' + ); + } + + for my $file ( $creq->upload ) { + my $upload = $creq->upload($file); + SKIP: + { + if ( $ENV{CATALYST_SERVER} ) { + skip 'Not testing for deleted file on remote server', 1; + } + ok( !-e $upload->tempname, 'Upload temp file was deleted' ); + } + } } { @@ -240,13 +282,75 @@ use Path::Class::Dir; is( $upload->type, $part->content_type, 'Upload Content-Type' ); is( $upload->size, length( $part->content ), 'Upload Content-Length' ); - is( $upload->filename, 'catalyst_130pix.gif' ); + is( $upload->filename, 'catalyst_130pix.gif', 'Upload Filename' ); + is( $upload->basename, 'catalyst_130pix.gif', 'Upload basename' ); + + SKIP: + { + if ( $ENV{CATALYST_SERVER} ) { + skip 'Not testing for deleted file on remote server', 1; + } + ok( !-e $upload->tempname, 'Upload temp file was deleted' ); + } } } -# test uploadtmp config var +# Test PUT request with application/octet-stream file gets deleted + +{ + my $body; + + my $request = PUT( + 'http://localhost/dump/body/', + 'Content-Type' => 'application/octet-stream', + 'Content' => 'foobarbaz', + 'Content-Length' => 9, + ); + + ok( my $response = request($request), 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + like( + $response->content, + qr/bless\( .* 'HTTP::Body::OctetStream' \)/s, + 'Content is a serialized HTTP::Body::OctetStream' + ); + + { + no strict 'refs'; + ok( + eval '$body = ' . substr( $response->content, 8 ), # FIXME - substr not needed in other test cases? + 'Unserialize HTTP::Body::OctetStream' + ) or warn $@; + } + + isa_ok( $body, 'HTTP::Body::OctetStream' ); + isa_ok($body->body, 'File::Temp'); + SKIP: + { + if ( $ENV{CATALYST_SERVER} ) { + skip 'Not testing for deleted file on remote server', 1; + } + + # JNAP, I added the following line in order to properly let + # the $env go out of scope so that the associated tempfile + # would be deleted. I think somewhere Catalyst::Test closed + # over ENV and holds state until a new command is issues but + # I can't find it. + + request GET 'http://localhost/'; + ok( !-e $body->body->filename, 'Upload temp file was deleted' ); + } +} + +# test uploadtmp config var +SKIP: { + if ( $ENV{CATALYST_SERVER} ) { + skip 'Not testing uploadtmp on remote server', 14; + } + my $creq; my $dir = "$FindBin::Bin/"; @@ -300,6 +404,8 @@ use Path::Class::Dir; is( $upload->size, length( $part->content ), 'Upload Content-Length' ); like( $upload->tempname, qr{\Q$dir\E}, 'uploadtmp' ); + + ok( !-e $upload->tempname, 'Upload temp file was deleted' ); } }