X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F01use.t;h=0fc29fe70b6218af66148ddc895134a778986a38;hb=44761c0069a2e8055efc3f45c11c42467556bf2a;hp=6072013116d9801c2ca72166678ec5aa69c39f7e;hpb=348fdd5a1e92dc75067e9d159186ce8cb236e0c3;p=catagits%2FHTTP-Body.git diff --git a/t/01use.t b/t/01use.t index 6072013..0fc29fe 100644 --- a/t/01use.t +++ b/t/01use.t @@ -8,23 +8,24 @@ use Path::Class; use Data::Dumper; for my $format (qw/multipart urlencoded/) { + for my $match ( glob file( $FindBin::Bin, 'data', $format, '*.dat' ) ) { my $file = file($match); my $name = $file->basename; $name =~ /^(\d+)-.*/; my $num = $1; - my $headers = - LoadFile( - file( $FindBin::Bin, 'data', $format, "$num-headers.yml" ) ); + my $headers = LoadFile( file( $FindBin::Bin, 'data', $format, "$num-headers.yml" ) ); + my $results = LoadFile( file( $FindBin::Bin, 'data', $format, "$num-results.yml" ) ); my $content = $file->open('<'); - my $body = HTTP::Body->new( $headers->{'Content-Type'}, - $headers->{'Content-Length'} ); - binmode $content; + my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} ); + + binmode $content, ':raw'; while ( $content->read( my $buffer, 1024 ) ) { $body->add($buffer); } - if ( $ENV{HTTP_Body_Debug} ) { + + if ( $ENV{HTTP_BODY_DEBUG} ) { warn Dumper( $body->param ); warn Dumper( $body->upload ); warn Dumper( $body->body ); @@ -35,7 +36,20 @@ for my $format (qw/multipart urlencoded/) { warn "body length : " . ( $body->body->stat )[7] if $body->body; warn "buffer : " . $body->buffer if $body->buffer; } - ok( $body->state eq 'done' ); + + for my $field ( keys %{ $body->upload } ) { + + my $value = $body->upload->{$field}; + + for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) { + delete $_->{tempname}; + } + } + + is_deeply( $body->body, $results->{body}, "$num-$format body" ); + is_deeply( $body->param, $results->{param}, "$num-$format param" ); + is_deeply( $body->upload, $results->{upload}, "$num-$format upload" ); + ok( $body->state eq 'done', "$num-$format state" ); } }