File: multi_apps.t

package info (click to toggle)
libdancer2-perl 0.400001%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,580 kB
  • sloc: perl: 8,461; makefile: 9
file content (48 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download | duplicates (6)
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
48
use strict;
use warnings;
use Test::More;
use Plack::Builder;
use Plack::Test;
use HTTP::Request::Common;

{
    package MyTestWiki;
    use Dancer2;
    get '/'     => sub { __PACKAGE__ };
    get '/wiki' => sub {'WIKI'};

    package MyTestForum;
    use Dancer2;
    get '/'      => sub { __PACKAGE__ };
    get '/forum' => sub {'FORUM'};
}

{
    my $app = builder {
        mount '/wiki'  => MyTestWiki->to_app;
        mount '/forum' => MyTestForum->to_app;
    };

    isa_ok( $app, 'CODE', 'Got app' );

    test_psgi $app, sub {
        my $cb = shift;

        is( $cb->( GET '/wiki' )->content, 'MyTestWiki', "Got wiki root" );
        is( $cb->( GET '/forum' )->content, 'MyTestForum', "Got forum root" );
    };
}

{
    my $app = Dancer2->psgi_app;
    isa_ok( $app, 'CODE', 'Got app' );

    test_psgi $app, sub {
        my $cb = shift;

        is( $cb->( GET '/wiki' )->content, 'WIKI', 'Got /wiki path' );
        is( $cb->( GET '/forum' )->content, 'FORUM', 'Got /forum path' );
    };
}

done_testing;