Skip to content

Commit

Permalink
tests demostrating the edge case fixed in eed850.
Browse files Browse the repository at this point in the history
  • Loading branch information
clkao committed Aug 8, 2010
1 parent eed850a commit 4bf0164
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ requires 'Try::Tiny';
recommends 'HTTP::Parser::XS';
recommends 'EV';
install_script 'bin/twiggy';
test_requires 'Test::Requires';
test_requires 'Test::More';
test_requires 'Test::TCP';
use_test_base;
Expand Down
51 changes: 51 additions & 0 deletions t/deflater.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use strict;
use warnings;
use Test::More qw(no_diag);
use Test::Requires qw( Plack::Middleware::Deflater LWP::UserAgent IO::Uncompress::Gunzip );
use Test::TCP;
use Plack::Loader;
use Plack::Request;
use HTTP::Response;
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);

use Plack::App::File;

use HTTP::Request::Common;

my $app = Plack::App::File->new( root => 't')->to_app;
$app = Plack::Middleware::Deflater->wrap($app);

open my $f, '>', "t/deflater_test.txt" or die $!;
print $f '1234567890' x 1000;
close $f;

END { unlink('t/deflater_test.txt') }

test_tcp(
client => sub {
my $port = shift;

my $ua = LWP::UserAgent->new;
$ua->timeout(2);
my $req = GET ("http://localhost:$port/deflater_test.txt");
$req->header('Accept-Encoding', 'gzip');
my $res = $ua->request($req);
if ($res->is_success) {

gunzip \$res->content => \(my $output)
or die "gunzip failed: $GunzipError\n";
is(length($output), 10000);
}
else {
ok(0);
}
},
server => sub {
my $port = shift;
my $server = Plack::Loader->load('Twiggy', port => $port, host => '127.0.0.1');
$server->run($app);
},
);

done_testing();

0 comments on commit 4bf0164

Please sign in to comment.