Date of last release in Changes files
[catagits/HTTP-Body.git] / t / 09rt88342-diff-regexp.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/lib";
8
9 use Test::More tests => 3;
10 use Test::Deep;
11
12 use Cwd;
13 use HTTP::Body;
14 use File::Spec::Functions;
15 use IO::File;
16 use PAML;
17 use File::Temp qw/ tempdir /;
18
19 my $path = catdir( getcwd(), 't', 'data', 'multipart' );
20
21 {
22   $HTTP::Body::MultiPart::file_temp_suffix = undef;
23   $HTTP::Body::MultiPart::basename_regexp = qr/(\.\w+(?:\.\w+)*)$/;
24
25   my $uploads = uploads_for('015');
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
53 sub 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 }