Changing default behavior of upload handling to stop taking over the upload extension...
[catagits/HTTP-Body.git] / t / 12rt88342-new.t
CommitLineData
29a092ff 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
7use lib "$FindBin::Bin/lib";
8
cc75c886 9use Test::More tests => 5;
29a092ff 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{
cc75c886 22 my $uploads = uploads_for('015');
29a092ff 23
24 {
25 my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload}{tempname} );
26 like(
cc75c886 27 $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/,
28 'everything is file_temp_suffix now'
29a092ff 29 );
30 }
31
32 {
33 my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload2}{tempname} );
34 like(
cc75c886 35 $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/,
36 'everything is file_temp_suffix now'
29a092ff 37 );
38 }
39
40 {
41 my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload3}{tempname} );
42 like(
cc75c886 43 $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/,
44 'everything is file_temp_suffix now'
45 );
46 }
47
48 {
49 my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload4}{tempname} );
50 like(
51 $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/,
52 'everything is file_temp_suffix now'
29a092ff 53 );
54 }
55
cc75c886 56 {
57 my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload5}{tempname} );
58 like(
59 $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/,
60 'everything is file_temp_suffix now'
61 );
62 }
29a092ff 63}
64
65sub uploads_for {
66 my $number = shift;
67
68 my $headers = PAML::LoadFile( catfile( $path, "$number-headers.pml" ) );
69 my $content = IO::File->new( catfile( $path, "$number-content.dat" ) );
70 my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
71 my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() );
72 $body->tmpdir($tempdir);
73
74 binmode $content, ':raw';
75
76 while ( $content->read( my $buffer, 1024 ) ) {
77 $body->add($buffer);
78 }
79
80 $body->cleanup(1);
81
82 return $body->upload;
83}