Fix for the fix...
[catagits/HTTP-Body.git] / t / 06octetstream.t
CommitLineData
239fb0d6 1use strict;
2use warnings;
3
712c90b5 4use FindBin;
5use lib "$FindBin::Bin/lib";
6
0a66fd23 7use Test::More tests => 12;
239fb0d6 8
9use Cwd;
10use HTTP::Body;
11use File::Spec::Functions;
12use IO::File;
712c90b5 13use PAML;
239fb0d6 14
15my $path = catdir( getcwd(), 't', 'data', 'octetstream' );
16
0a66fd23 17for ( my $i = 1 ; $i <= 3 ; $i++ ) {
239fb0d6 18
19 my $test = sprintf( "%.3d", $i );
712c90b5 20 my $headers = PAML::LoadFile( catfile( $path, "$test-headers.pml" ) );
239fb0d6 21 my $results =
22 slurp_fh( IO::File->new( catfile( $path, "$test-results.dat" ) ) );
23 my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
24 my $body = HTTP::Body->new( $headers->{'Content-Type'},
25 $headers->{'Content-Length'} );
26
27 binmode $content, ':raw';
28
29 while ( $content->read( my $buffer, 1024 ) ) {
30 $body->add($buffer);
31 }
32
33 isa_ok( $body->body, 'File::Temp', "$test OctetStream body isa" );
34 my $data = slurp_fh( $body->body );
35 is_deeply( $data, $results, "$test UrlEncoded body" );
36 cmp_ok( $body->state, 'eq', 'done', "$test UrlEncoded state" );
37 cmp_ok(
38 $body->length, '==',
0a66fd23 39 $body->content_length,
239fb0d6 40 "$test UrlEncoded length"
41 );
42}
43
44sub slurp_fh {
45 my ($fh) = @_;
46 my $data = '';
47 while ( $fh->read( my $buffer, 1024 ) ) {
48 $data .= $buffer;
49 }
50 $data;
51}