Commit | Line | Data |
6a7b9183 |
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 => 4; |
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 | my $uploads = uploads_for('001'); |
23 | |
24 | like( |
25 | $uploads->{upload2}{tempname}, qr/\.pl$/, |
26 | 'tempname preserves .pl suffix' |
27 | ); |
28 | |
29 | unlike( |
30 | $uploads->{upload4}{tempname}, qr/\..+$/, |
31 | 'tempname for upload4 has no suffix' |
32 | ); |
33 | } |
34 | |
35 | { |
36 | my $uploads = uploads_for('006'); |
37 | |
38 | like( |
39 | $uploads->{upload2}{tempname}, qr/\.pl$/, |
40 | 'tempname preserves .pl suffix with Windows filename' |
41 | ); |
42 | } |
43 | |
44 | { |
45 | my $uploads = uploads_for('014'); |
46 | |
47 | like( |
48 | $uploads->{upload}{tempname}, qr/\.foo\.txt$/, |
49 | 'tempname preserves .foo.txt suffix' |
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 | } |