File: server_standalone.t

package info (click to toggle)
libdancer2-perl 0.152000%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,820 kB
  • ctags: 536
  • sloc: perl: 8,034; sh: 51; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,019 bytes parent folder | download
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
use Test::More;
use strict;
use warnings;
use Encode;
use utf8;

use Test::TCP 1.13;
use HTTP::Headers;
use HTTP::Request;
use LWP::UserAgent;

plan tests => 7;

Test::TCP::test_tcp(
    client => sub {
        my $port = shift;
        my $ua   = LWP::UserAgent->new;
        # Ensure the standalone standaloneerver responds to all the
        # HTTP methods the DSL supports
        for my $method ( qw/HEAD GET PUT POST DELETE OPTIONS PATCH/ ) {
            my $req = HTTP::Request->new($method => "http://127.0.0.1:$port/foo");
            my $res = $ua->request($req);
            ok( $res->is_success, "$method return a 200 response");
        }
    },
    server => sub {
        my $port = shift;
        use Dancer2;
        set charset => 'utf-8';

        any '/foo' => sub {
            header "Allow" => "HEAD,GET,PUT,POST,DELETE,OPTIONS,PATCH";
            "foo";
        };

        # we're overiding a RO attribute only for this test!
        Dancer2->runner->{'port'} = $port;
        start;
    },
);