summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-12-21 18:38:03 -0600
committerJesse Luehrs <doy@tozt.net>2010-12-21 18:38:03 -0600
commitfec68e5e7b2a512264e31edc4f9f4adc4d55df73 (patch)
tree9c0982af31509531010991c96d9802d9b5abd2c8 /t
parent0df5ab8ffd82030223b2785976215660a6d52626 (diff)
downloadplack-client-fec68e5e7b2a512264e31edc4f9f4adc4d55df73.tar.gz
plack-client-fec68e5e7b2a512264e31edc4f9f4adc4d55df73.zip
test to sketch out an api
Diffstat (limited to 't')
-rw-r--r--t/01-basic.t75
1 files changed, 75 insertions, 0 deletions
diff --git a/t/01-basic.t b/t/01-basic.t
new file mode 100644
index 0000000..2bb5150
--- /dev/null
+++ b/t/01-basic.t
@@ -0,0 +1,75 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::TCP;
+
+use Plack::Client;
+
+test_tcp(
+ client => sub {
+ my $port = shift;
+
+ my $client = Plack::Client->new;
+ isa_ok($client, 'Plack::Client');
+
+ {
+ my $res = $client->get('http://localhost:5000/');
+ isa_ok($res, 'Plack::Response');
+ is($res->status, 200, "right status");
+ is_deeply($res->headers, ["Content-Type" => "text/plain"],
+ "right headers");
+ is($res->body, '/', "right body");
+ }
+
+ {
+ my $res = $client->get('http://localhost:5000/foo');
+ isa_ok($res, 'Plack::Response');
+ is($res->status, 200, "right status");
+ is_deeply($res->headers, ["Content-Type" => "text/plain"],
+ "right headers");
+ is($res->body, '/foo', "right body");
+ }
+ },
+ server => sub {
+ my $port = shift;
+ exec('plackup', '--port', $port, '-e', 'sub { [ 200, ["Content-Type" => "text/plain"], [shift->{PATH_INFO}] ] }');
+ },
+);
+
+{
+ my $apps = {
+ foo => sub {
+ [
+ 200,
+ ["Content-Type" => "text/plain"],
+ [scalar reverse shift->{PATH_INFO}]
+ ]
+ },
+ };
+ my $client = Plack::Client->new(apps => $apps);
+ isa_ok($client, 'Plack::Client');
+ is($client->apps, $apps, "got apps back");
+ is($client->app_for('foo'), $apps->{foo}, "got the right app");
+ is($client->app_for('bar'), undef, "didn't get nonexistent app");
+
+ {
+ my $res = $client->get('psgi://foo/');
+ isa_ok($res, 'Plack::Response');
+ is($res->status, 200, "right status");
+ is_deeply($res->headers, ["Content-Type" => "text/plain"],
+ "right headers");
+ is($res->body, '/', "right body");
+ }
+
+ {
+ my $res = $client->get('psgi://foo/foo');
+ isa_ok($res, 'Plack::Response');
+ is($res->status, 200, "right status");
+ is_deeply($res->headers, ["Content-Type" => "text/plain"],
+ "right headers");
+ is($res->body, 'oof/', "right body");
+ }
+}
+
+done_testing;