| 1 |
#!perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test::More tests => 9; |
| 7 |
use Plack::Test; |
| 8 |
use HTTP::Request::Common; |
| 9 |
|
| 10 |
{ |
| 11 |
package App1; |
| 12 |
use Dancer2; |
| 13 |
|
| 14 |
get '/' => sub {'App1'}; |
| 15 |
|
| 16 |
get '/forward' => sub { |
| 17 |
forward '/'; |
| 18 |
::ok( 0, 'Foward not returning right away!' ); |
| 19 |
}; |
| 20 |
|
| 21 |
get '/forward_to_new' => sub { |
| 22 |
forward '/new'; |
| 23 |
::ok( 0, 'Foward not returning right away!' ); |
| 24 |
}; |
| 25 |
} |
| 26 |
|
| 27 |
{ |
| 28 |
package App2; |
| 29 |
use Dancer2; |
| 30 |
get '/' => sub {'App2'}; |
| 31 |
get '/new' => sub {'New'}; |
| 32 |
} |
| 33 |
|
| 34 |
{ |
| 35 |
# test each single app |
| 36 |
my $app1 = App1->to_app; |
| 37 |
test_psgi $app1, sub { |
| 38 |
my $cb = shift; |
| 39 |
is( $cb->( GET '/' )->code, 200, '[GET /] OK' ); |
| 40 |
is( $cb->( GET '/' )->content, 'App1', '[GET /] OK content' ); |
| 41 |
|
| 42 |
is( $cb->( GET '/forward' )->code, 200, '[GET /forward] OK' ); |
| 43 |
is( |
| 44 |
$cb->( GET '/forward' )->content, |
| 45 |
'App1', |
| 46 |
'[GET /forward] OK content' |
| 47 |
); |
| 48 |
|
| 49 |
is( |
| 50 |
$cb->( GET '/forward_to_new' )->code, |
| 51 |
404, |
| 52 |
'Cannot find /new', |
| 53 |
); |
| 54 |
}; |
| 55 |
|
| 56 |
my $app2 = App2->to_app; |
| 57 |
test_psgi $app2, sub { |
| 58 |
my $cb = shift; |
| 59 |
is( $cb->( GET '/' )->code, 200, '[GET /] OK' ); |
| 60 |
is( $cb->( GET '/' )->content, 'App2', '[GET /] OK content' ); |
| 61 |
}; |
| 62 |
} |
| 63 |
|
| 64 |
note 'Old format using psgi_app to loop over multiple apps'; { |
| 65 |
# test global |
| 66 |
my $app = Dancer2->psgi_app; |
| 67 |
test_psgi $app, sub { |
| 68 |
my $cb = shift; |
| 69 |
|
| 70 |
is( |
| 71 |
$cb->( GET '/forward_to_new' )->code, |
| 72 |
200, |
| 73 |
'[GET /forward_to_new] OK', |
| 74 |
); |
| 75 |
|
| 76 |
is( |
| 77 |
$cb->( GET '/forward_to_new' )->content, |
| 78 |
'New', |
| 79 |
'[GET /forward_to_new] OK content', |
| 80 |
); |
| 81 |
}; |
| 82 |
} |
| 83 |
|