| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use FindBin; |
| 4 |
use lib "$FindBin::Bin/"; |
| 5 |
|
| 6 |
use Test::More; |
| 7 |
|
| 8 |
{ |
| 9 |
package App1; |
| 10 |
use Dancer2; |
| 11 |
use TestPlugin; |
| 12 |
set logger => 'null'; |
| 13 |
get '/' => sub { |
| 14 |
my @apps = test(); |
| 15 |
::is( $apps[0], $apps[1], 'Plugin reports the same app' ); |
| 16 |
::is( $apps[0], app->name, 'Plugin reports the correct app' ); |
| 17 |
return 'Cookie: ' . (response()->headers()->header('Set-Cookie') // ''); |
| 18 |
|
| 19 |
}; |
| 20 |
|
| 21 |
package App2; |
| 22 |
use Dancer2; |
| 23 |
use TestPlugin; |
| 24 |
set logger => 'null'; |
| 25 |
get '/' => sub { |
| 26 |
my @apps = test(); |
| 27 |
::is( $apps[0], $apps[1], 'Plugin reports the same app' ); |
| 28 |
::is( $apps[0], app->name, 'Plugin reports the correct app' ); |
| 29 |
return 'Cookie: ' . (response()->headers()->header('Set-Cookie') // ''); |
| 30 |
}; |
| 31 |
} |
| 32 |
|
| 33 |
use Plack::Test; |
| 34 |
use Plack::Builder; |
| 35 |
use HTTP::Request::Common; |
| 36 |
|
| 37 |
my $app1 = Plack::Test->create( App1->to_app() ); |
| 38 |
my $app2 = Plack::Test->create( App2->to_app() ); |
| 39 |
|
| 40 |
my $cookie = $app1->request(GET '/')->header('Set-Cookie'); |
| 41 |
is($cookie, 'App1=foo; Path=/', 'Got cookie from app1'); |
| 42 |
$cookie = $app2->request(GET '/')->header('Set-Cookie'); |
| 43 |
is($cookie, 'App2=foo; Path=/', 'Got cookie from app2'); |
| 44 |
$cookie = $app1->request(GET '/')->header('Set-Cookie'); |
| 45 |
is($cookie, 'App1=foo; Path=/', 'Got cookie again from app1'); |
| 46 |
|
| 47 |
done_testing(); |