File: 09rt88342.t

package info (click to toggle)
libhttp-body-perl 1.19-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 524 kB
  • ctags: 59
  • sloc: perl: 825; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,546 bytes parent folder | download | duplicates (4)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!perl

use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/lib";

use Test::More tests => 3;
use Test::Deep;

use Cwd;
use HTTP::Body;
use File::Spec::Functions;
use IO::File;
use PAML;
use File::Temp qw/ tempdir /;

my $path = catdir( getcwd(), 't', 'data', 'multipart' );

{
  $HTTP::Body::MultiPart::basename_regexp = qr/(\.\w+(?:\.\w+)*)$/;

    my $uploads = uploads_for('015');

	{
		my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload}{tempname} );	
		like(
			$file, qr/^.{10}\.tar\.gz\.Z$/,
			'tempname preserves .tar.gz.Z suffix'
		);
	}

  {
    my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload2}{tempname} );  
    like(
      $file, qr/^.{10}\.png$/,
      'tempname preserves .png suffix'
    );
  }

  {
    my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload3}{tempname} );  
    like(
      $file, qr/^.{10}\.txt$/,
      'tempname preserves .txt suffix'
    );
  }

}

sub uploads_for {
    my $number = shift;

    my $headers = PAML::LoadFile( catfile( $path, "$number-headers.pml" ) );
    my $content = IO::File->new( catfile( $path, "$number-content.dat" ) );
    my $body    = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
    my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() );
    $body->tmpdir($tempdir);

    binmode $content, ':raw';

    while ( $content->read( my $buffer, 1024 ) ) {
        $body->add($buffer);
    }

    $body->cleanup(1);

    return $body->upload;
}