diff options
author | franck cuny <franck@lumberjaph.net> | 2010-02-28 11:13:58 +0100 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-02-28 11:13:58 +0100 |
commit | b036a6823527fa6f781ef015783bc749fbfb68d2 (patch) | |
tree | 2aaaf12e0b6c3ce17737c2cdc7cf72c42d90a6ac | |
parent | add etag header to response (diff) | |
download | plack-middleware-etag-b036a6823527fa6f781ef015783bc749fbfb68d2.tar.gz |
basic tests
-rw-r--r-- | t/01_basic.t | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/t/01_basic.t b/t/01_basic.t new file mode 100644 index 0000000..0bc49c6 --- /dev/null +++ b/t/01_basic.t @@ -0,0 +1,53 @@ +use strict; +use warnings; +use Test::More; + +use Digest::SHA; + +use Plack::Test; +use Plack::Builder; +use HTTP::Request::Common; + +my $content = [qw/hello world/]; + +my $handler = builder { + enable "Plack::Middleware::ETag"; + sub { [ '200', [ 'Content-Type' => 'text/html' ], $content ] }; +}; + +my $second_handler = builder { + enable "Plack::Middleware::ETag"; + sub { + [ + '200', [ 'Content-Type' => 'text/html', 'ETag' => '123' ], + $content + ]; + }; +}; + +test_psgi + app => $handler, + client => sub { + my $cb = shift; + { + my $req = GET "http://localhost/"; + my $res = $cb->($req); + ok $res->header('ETag'); + my $sha = Digest::SHA->new->add(@$content); + is $res->header('ETag'), $sha->hexdigest; + } +}; + +test_psgi + app => $second_handler, + client => sub { + my $cb = shift; + { + my $req = GET "http://localhost/"; + my $res = $cb->($req); + ok $res->header('ETag'); + is $res->header('ETag'), '123'; + } +}; + +done_testing; |