File: multi_apps_forward.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 (83 lines) | stat: -rw-r--r-- 1,750 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!perl

use strict;
use warnings;

use Test::More tests => 9;
use Plack::Test;
use HTTP::Request::Common;

{
    package App1;
    use Dancer2;

    get '/' => sub {'App1'};

    get '/forward' => sub {
        forward '/';
        ::ok( 0, 'Foward not returning right away!' );
    };

    get '/forward_to_new' => sub {
        forward '/new';
        ::ok( 0, 'Foward not returning right away!' );
    };
}

{
    package App2;
    use Dancer2;
    get '/'    => sub {'App2'};
    get '/new' => sub {'New'};
}

{
    # test each single app
    my $app1 = App1->to_app;
    test_psgi $app1, sub {
        my $cb = shift;
        is( $cb->( GET '/' )->code, 200, '[GET /] OK' );
        is( $cb->( GET '/' )->content, 'App1', '[GET /] OK content' );

        is( $cb->( GET '/forward' )->code, 200, '[GET /forward] OK' );
        is(
            $cb->( GET '/forward' )->content,
            'App1',
            '[GET /forward] OK content'
        );

        is(
            $cb->( GET '/forward_to_new' )->code,
            404,
            'Cannot find /new',
        );
    };

    my $app2 = App2->to_app;
    test_psgi $app2, sub {
        my $cb = shift;
        is( $cb->( GET '/' )->code, 200, '[GET /] OK' );
        is( $cb->( GET '/' )->content, 'App2', '[GET /] OK content' );
    };
}

note 'Old format using psgi_app to loop over multiple apps'; {
    # test global
    my $app = Dancer2->psgi_app;
    test_psgi $app, sub {
        my $cb = shift;

        is(
            $cb->( GET '/forward_to_new' )->code,
            200,
            '[GET /forward_to_new] OK',
        );

        is(
            $cb->( GET '/forward_to_new' )->content,
            'New',
            '[GET /forward_to_new] OK content',
        );
    };
}