summary refs log tree commit diff
path: root/t/spore-middleware
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2011-07-11 16:45:32 +0200
committerfranck cuny <franck@lumberjaph.net>2011-07-26 13:21:01 +0200
commitf9ecf8d9f17d04de2d0853ca71aac055b44fa829 (patch)
tree4dfb18e4face2c523ab471c1402d19d6ea5a2c10 /t/spore-middleware
parentadd documentation for tracing (diff)
downloadnet-http-spore-f9ecf8d9f17d04de2d0853ca71aac055b44fa829.tar.gz
add test for loading a middleware outside N::H::Spore namespace
Signed-off-by: franck cuny <franck@lumberjaph.net>
Diffstat (limited to 't/spore-middleware')
-rw-r--r--t/spore-middleware/ns.t44
1 files changed, 44 insertions, 0 deletions
diff --git a/t/spore-middleware/ns.t b/t/spore-middleware/ns.t
new file mode 100644
index 0000000..3d8a57c
--- /dev/null
+++ b/t/spore-middleware/ns.t
@@ -0,0 +1,44 @@
+use strict;
+use warnings;
+use Test::More;
+use Net::HTTP::Spore;
+use Test::Exception;
+
+package test::runtime;
+
+use Moose;
+extends 'Net::HTTP::Spore::Middleware';
+
+sub call {
+    my ( $self, $req) = @_;
+    $self->response_cb(
+        sub {
+            my $res = shift;
+            $res->header('X-Test' => 1);
+        }
+    );
+}
+
+package main;
+
+my $mock_server = {
+    '/show' => sub {
+        my $req = shift;
+        $req->new_response( 200, [ 'Content-Type' => 'text/plan' ], 'ok');
+    },
+};
+
+ok my $client =
+  Net::HTTP::Spore->new_from_spec( 't/specs/api.json',
+    base_url => 'http://localhost' );
+
+dies_ok { $client->enable('test::runtime') }
+"can't load unknown middleware in N::H::Spore namespace";
+
+$client->enable('+test::runtime');
+$client->enable('Mock', tests => $mock_server);
+
+my $res = $client->get_info();
+ok $res->header('X-Test');
+
+done_testing;