about summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-02-28 11:13:58 +0100
committerfranck cuny <franck@lumberjaph.net>2010-02-28 11:13:58 +0100
commitb036a6823527fa6f781ef015783bc749fbfb68d2 (patch)
tree2aaaf12e0b6c3ce17737c2cdc7cf72c42d90a6ac
parentadd etag header to response (diff)
downloadplack-middleware-etag-b036a6823527fa6f781ef015783bc749fbfb68d2.tar.gz
basic tests
-rw-r--r--t/01_basic.t53
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;