Commit | Line | Data |
a9df1200 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
1084e914 |
6 | use Test::More |
7 | |
8 | eval { require YAML; import YAML 'LoadFile'; }; |
9 | if ($@) { |
10 | eval { require YAML::Syck; import YAML::Syck 'LoadFile'; } |
11 | } |
12 | |
13 | plan skip_all => 'Tests need YAML or YAML::Syck' if $@; |
14 | |
15 | plan tests => 5; |
a9df1200 |
16 | |
17 | use Cwd; |
18 | use HTTP::Body; |
19 | use File::Spec::Functions; |
20 | use IO::File; |
a9df1200 |
21 | |
22 | my $path = catdir( getcwd(), 't', 'data', 'urlencoded' ); |
23 | |
24 | for ( my $i = 1; $i <= 1; $i++ ) { |
25 | |
26 | my $test = sprintf( "%.3d", $i ); |
27 | my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) ); |
28 | my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) ); |
29 | my $content = IO::File->new( catfile( $path, "$test-content.dat" ) ); |
30 | my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} ); |
31 | |
32 | binmode $content, ':raw'; |
33 | |
34 | while ( $content->read( my $buffer, 1024 ) ) { |
35 | $body->add($buffer); |
36 | } |
37 | |
38 | is_deeply( $body->body, $results->{body}, "$test UrlEncoded body" ); |
39 | is_deeply( $body->param, $results->{param}, "$test UrlEncoded param" ); |
40 | is_deeply( $body->upload, $results->{upload}, "$test UrlEncoded upload" ); |
41 | cmp_ok( $body->state, 'eq', 'done', "$test UrlEncoded state" ); |
42 | cmp_ok( $body->length, '==', $headers->{'Content-Length'}, "$test UrlEncoded length" ); |
43 | } |