Changing default behavior of upload handling to stop taking over the upload extension...
[catagits/HTTP-Body.git] / t / 09rt88342-diff-regexp.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{
cc75c886 22 $HTTP::Body::MultiPart::file_temp_suffix = undef;
29a092ff 23 $HTTP::Body::MultiPart::basename_regexp = qr/(\.\w+(?:\.\w+)*)$/;
24
cc75c886 25 my $uploads = uploads_for('015');
29a092ff 26
27 {
28 my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload}{tempname} );
29 like(
30 $file, qr/^.{10}\.tar\.gz\.Z$/,
31 'tempname preserves .tar.gz.Z suffix'
32 );
33 }
34
35 {
36 my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload2}{tempname} );
37 like(
38 $file, qr/^.{10}\.png$/,
39 'tempname preserves .png suffix'
40 );
41 }
42
43 {
44 my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload3}{tempname} );
45 like(
46 $file, qr/^.{10}\.txt$/,
47 'tempname preserves .txt suffix'
48 );
49 }
50
51}
52
53sub uploads_for {
54 my $number = shift;
55
56 my $headers = PAML::LoadFile( catfile( $path, "$number-headers.pml" ) );
57 my $content = IO::File->new( catfile( $path, "$number-content.dat" ) );
58 my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
59 my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() );
60 $body->tmpdir($tempdir);
61
62 binmode $content, ':raw';
63
64 while ( $content->read( my $buffer, 1024 ) ) {
65 $body->add($buffer);
66 }
67
68 $body->cleanup(1);
69
70 return $body->upload;
71}