From: Tomas Doran Date: Wed, 3 Dec 2008 09:08:58 +0000 (+0000) Subject: Add extra HTTP::Body tests I have had hanging around in my local repos for months X-Git-Tag: 5.8000_04~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=c4b09639360d8883906ab496552f2021a73bf34f Add extra HTTP::Body tests I have had hanging around in my local repos for months --- diff --git a/Changes b/Changes index c6b66ca..af282c3 100644 --- a/Changes +++ b/Changes @@ -22,6 +22,8 @@ - Change Catalyst::ClassData to tweak the symbol table inline for performance after profiling (mst) - Fix POD typo in finalize_error (jhannah) + - Add tests to ensure that we delete the temp files created by + HTTP::Body's OctetStream parser (t0m) 5.8000_03 2008-10-14 14:13:00 - Fix forwarding to Catalyst::Action objects (Rafael Kitover). diff --git a/t/aggregate/live_engine_request_uploads.t b/t/aggregate/live_engine_request_uploads.t index 2454330..c69dfae 100644 --- a/t/aggregate/live_engine_request_uploads.t +++ b/t/aggregate/live_engine_request_uploads.t @@ -6,7 +6,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; -use Test::More tests => 88; +use Test::More tests => 96; use Catalyst::Test 'TestApp'; use Catalyst::Request; @@ -244,6 +244,41 @@ use Path::Class::Dir; } } +# 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'); + + ok( !-e $body->body->filename, 'Upload temp file was deleted' ); +} + # test uploadtmp config var { diff --git a/t/lib/TestApp/Controller/Dump.pm b/t/lib/TestApp/Controller/Dump.pm index df33eb5..4b20f33 100644 --- a/t/lib/TestApp/Controller/Dump.pm +++ b/t/lib/TestApp/Controller/Dump.pm @@ -29,4 +29,9 @@ sub response : Action Relative { $c->forward('TestApp::View::Dump::Response'); } +sub body : Action Relative { + my ( $self, $c ) = @_; + $c->forward('TestApp::View::Dump::Body'); +} + 1; diff --git a/t/lib/TestApp/View/Dump/Body.pm b/t/lib/TestApp/View/Dump/Body.pm new file mode 100644 index 0000000..369ccbd --- /dev/null +++ b/t/lib/TestApp/View/Dump/Body.pm @@ -0,0 +1,11 @@ +package TestApp::View::Dump::Body; + +use strict; +use base qw[TestApp::View::Dump]; + +sub process { + my ( $self, $c ) = @_; + return $self->SUPER::process( $c, $c->request->{_body} ); # FIXME, accessor doesn't work? +} + +1;