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 84 85 86 87 88 89 90 91 92
|
#!perl
use strict;
use warnings;
use Test::More tests => 25;
use Plack::Test;
use HTTP::Request::Common;
{ package App1; use Dancer2; get '/1' => sub {1}; }
{ package App2; use Dancer2; get '/2' => sub {2}; }
{ package App3; use Dancer2; get '/3' => sub {3}; }
sub is_available {
my ( $cb, @apps ) = @_;
foreach my $app (@apps) {
is( $cb->( GET "/$app" )->content, $app, "App$app available" );
}
}
sub isnt_available {
my ( $cb, @apps ) = @_;
foreach my $app (@apps) {
is(
$cb->( GET "/$app" )->code,
404,
"App$app is not available",
);
}
}
note 'All Apps'; {
my $app = Dancer2->psgi_app;
isa_ok( $app, 'CODE', 'Got PSGI app' );
test_psgi $app, sub {
my $cb = shift;
is_available( $cb, 1, 2, 3 );
};
}
note 'Specific Apps by parameters'; {
my @apps = @{ Dancer2->runner->apps }[ 0, 2 ];
is( scalar @apps, 2, 'Took two apps from the Runner' );
my $app = Dancer2->psgi_app(\@apps);
isa_ok( $app, 'CODE', 'Got PSGI app' );
test_psgi $app, sub {
my $cb = shift;
is_available( $cb, 1, 3 );
isnt_available( $cb, 2 );
};
}
note 'Specific Apps via App objects'; {
my $app = App2->psgi_app;
isa_ok( $app, 'CODE', 'Got PSGI app' );
test_psgi $app, sub {
my $cb = shift;
is_available( $cb, 2 );
isnt_available( $cb, 1, 3 );
};
};
note 'Specific apps by App names'; {
my $app = Dancer2->psgi_app( [ 'App1', 'App3' ] );
isa_ok( $app, 'CODE', 'Got PSGI app' );
test_psgi $app, sub {
my $cb = shift;
isnt_available( $cb, 2 );
is_available( $cb, 1, 3 );
};
}
note 'Specific apps by App names with regular expression, v1'; {
my $app = Dancer2->psgi_app( [ qr/^App1$/, qr/^App3$/ ] );
isa_ok( $app, 'CODE', 'Got PSGI app' );
test_psgi $app, sub {
my $cb = shift;
isnt_available( $cb, 2 );
is_available( $cb, 1, 3 );
};
}
note 'Specific apps by App names with regular expression, v2'; {
my $app = Dancer2->psgi_app( [ qr/^App(2|3)$/ ] );
isa_ok( $app, 'CODE', 'Got PSGI app' );
test_psgi $app, sub {
my $cb = shift;
isnt_available( $cb, 1 );
is_available( $cb, 2, 3 );
};
}
|