proposal to fix problem when we lose multipart meta info
[catagits/HTTP-Body.git] / t / 09rt88342.t
CommitLineData
29a092ff 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
7use lib "$FindBin::Bin/lib";
8
9use Test::More tests => 3;
10use Test::Deep;
11
12use Cwd;
13use HTTP::Body;
14use File::Spec::Functions;
15use IO::File;
16use PAML;
17use File::Temp qw/ tempdir /;
18
19my $path = catdir( getcwd(), 't', 'data', 'multipart' );
20
21{
22 $HTTP::Body::MultiPart::basename_regexp = qr/(\.\w+(?:\.\w+)*)$/;
23
24 my $uploads = uploads_for('015');
25
26 {
27 my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload}{tempname} );
28 like(
29 $file, qr/^.{10}\.tar\.gz\.Z$/,
30 'tempname preserves .tar.gz.Z suffix'
31 );
32 }
33
34 {
35 my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload2}{tempname} );
36 like(
37 $file, qr/^.{10}\.png$/,
38 'tempname preserves .png suffix'
39 );
40 }
41
42 {
43 my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload3}{tempname} );
44 like(
45 $file, qr/^.{10}\.txt$/,
46 'tempname preserves .txt suffix'
47 );
48 }
49
50}
51
52sub uploads_for {
53 my $number = shift;
54
55 my $headers = PAML::LoadFile( catfile( $path, "$number-headers.pml" ) );
56 my $content = IO::File->new( catfile( $path, "$number-content.dat" ) );
57 my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
58 my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() );
59 $body->tmpdir($tempdir);
60
61 binmode $content, ':raw';
62
63 while ( $content->read( my $buffer, 1024 ) ) {
64 $body->add($buffer);
65 }
66
67 $body->cleanup(1);
68
69 return $body->upload;
70}