File: octetstream.t

package info (click to toggle)
libhttp-entity-parser-perl 0.18-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 484 kB
  • ctags: 26
  • sloc: perl: 376; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,052 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use strict;
use warnings;
use Test::More;
use t::Util;
use HTTP::Entity::Parser;
use Cwd;
use File::Spec::Functions;
use Hash::MultiValue;

my $path = catdir( getcwd(), 't', '02_http_body', 'data', 'octetstream' );

for my $i ( 1..3 ) {
    my $test    = sprintf( "%03d", $i );

    my $headers = paml_loadfile( catfile( $path, "$test-headers.pml" ) );
    open(my $content, '<:unix',catfile( $path, "$test-content.dat" ) );
    my $results = slurp( catfile( $path, "$test-results.dat" ) );
    my $env = build_env($headers, $content);

    my $parser = HTTP::Entity::Parser->new();
    $parser->register('application/octet-stream','HTTP::Entity::Parser::OctetStream');
    my ($params, $uploads) = $parser->parse($env);

    my $hash = Hash::MultiValue->new(@$params);
    is_deeply([$hash->keys], [], "[$i] param_order");
    is_deeply($hash->as_hashref_mixed, {}, "[$i] param");
    is_deeply($uploads, []);
    my $data = do {
        local $/;
        my $fh = $env->{'psgi.input'};
        <$fh>;
    };
    is($data, $results);
}

done_testing;