File: basic.t

package info (click to toggle)
libplack-test-externalserver-perl 0.02-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 256 kB
  • sloc: perl: 234; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 1,202 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use strict;
use warnings;
use Test::More;

BEGIN { $ENV{PLACK_TEST_IMPL} = 'ExternalServer' }
use Plack::Test;

use Test::TCP;
use Plack::Loader;
use HTTP::Request::Common;

my $app = sub {
    my ($env) = @_;
    return [ 200, ['Content-Type' => 'text/plain'], [$env->{REQUEST_URI}] ];
};

test_tcp
    client => sub {
        my ($port) = @_;

        test_psgi
            uri => "http://127.0.0.1:${port}/foo",
            client => sub {
                my ($cb) = @_;
                my $res = $cb->(GET '/moo');
                ok($res->is_success);
                is($res->content, '/foo/moo');
            };

        local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://127.0.0.1:${port}/base";

        test_psgi
            uri => "http://127.0.0.1:${port}/foo",
            client => sub {
                my ($cb) = @_;
                my $res = $cb->(GET '/moo');
                ok($res->is_success);
                is($res->content, '/base/moo', 'env takes precedence over uri argument');
            };
    },
    server => sub {
        my ($port) = @_;
        my $server = Plack::Loader->auto(port => $port, host => '127.0.0.1');
        $server->run($app);
    };

done_testing;