Commit | Line | Data |
239fb0d6 |
1 | use strict; |
2 | use warnings; |
3 | |
712c90b5 |
4 | use FindBin; |
5 | use lib "$FindBin::Bin/lib"; |
6 | |
0a66fd23 |
7 | use Test::More tests => 12; |
239fb0d6 |
8 | |
9 | use Cwd; |
10 | use HTTP::Body; |
11 | use File::Spec::Functions; |
12 | use IO::File; |
712c90b5 |
13 | use PAML; |
239fb0d6 |
14 | |
15 | my $path = catdir( getcwd(), 't', 'data', 'octetstream' ); |
16 | |
0a66fd23 |
17 | for ( 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 | |
44 | sub slurp_fh { |
45 | my ($fh) = @_; |
46 | my $data = ''; |
47 | while ( $fh->read( my $buffer, 1024 ) ) { |
48 | $data .= $buffer; |
49 | } |
50 | $data; |
51 | } |