Permalink
Browse files

moved another test to Test::TCP for sessions

  • Loading branch information...
1 parent 21394a3 commit 3c08725aecd15a04569d844704da7190ee663c3d Alexis Sukrieh committed Oct 30, 2012
Showing with 54 additions and 17 deletions.
  1. +14 −2 t/session_engines.t
  2. +40 −15 t/shared_engines.t
View
@@ -12,14 +12,13 @@ my $tempdir = File::Temp::tempdir(CLEANUP => 1, TMPDIR => 1);
my @clients = qw(one two three);
my @engines = qw(YAML Simple);
+my $SESSION_DIR;
if ($ENV{DANCER_TEST_COOKIE}) {
push @engines, "cookie";
setting(session_cookie_key => "secret/foo*@!");
}
-plan tests => 3 * scalar(@clients) * scalar(@engines);
-
foreach my $engine (@engines) {
note "Testing engine $engine";
@@ -41,6 +40,9 @@ foreach my $engine (@engines) {
$res = $ua->get("http://127.0.0.1:$port/read_session");
like $res->content, qr/name='$client'/,
"session looks good for client $client";
+
+ $res = $ua->get("http://127.0.0.1:$port/cleanup");
+ ok($res->is_success, "cleanup done for $client");
}
File::Temp::cleanup();
@@ -60,6 +62,14 @@ foreach my $engine (@engines) {
"name='$name'";
};
+ get '/cleanup' => sub {
+ my $session = engine('session');
+ if (ref($session) eq 'Dancer::Session::YAML') {
+ unlink $session->yaml_file($session->id) or die "unable to rm: $!";
+ }
+ 1;
+ };
+
setting appdir => $tempdir;
setting(session => $engine);
@@ -74,4 +84,6 @@ foreach my $engine (@engines) {
},
);
}
+done_testing;
+
View
@@ -1,27 +1,52 @@
use strict;
use warnings;
+
+use File::Spec;
+use File::Temp 0.22;
+use LWP::UserAgent;
use Test::More;
+use Test::TCP 1.13;
+use YAML;
+
+my $tempdir = File::Temp::tempdir(CLEANUP => 1, TMPDIR => 1);
+
+Test::TCP::test_tcp(
+ client => sub {
+ my $port = shift;
+
+ my $ua = LWP::UserAgent->new;
+ $ua->cookie_jar({file => "$tempdir/.cookies.txt"});
+
+ my $res = $ua->get("http://127.0.0.1:$port/main");
+ like $res->content, qr{42}, "session is set in main";
-BEGIN {
- use Dancer 2.0;
- set session => 'Simple';
- engine('session')->{'__marker__'} = 1;
-}
+ $res = $ua->get("http://127.0.0.1:$port/in_foo");
+ like $res->content, qr{42}, "session is set in foo";
-use t::lib::Foo with => { session => engine('session') };
+ my $engine = t::lib::Foo->dsl->engine('session');
+ is $engine->{__marker__}, 1, "the session engine in subapp is the same";
-use Data::Dumper;
+ File::Temp::cleanup();
+ },
+ server => sub {
+ my $port = shift;
-get '/main' => sub {
- session('test' => 42);
-};
+ BEGIN {
+ use Dancer 2.0;
+ set session => 'Simple';
+ engine('session')->{'__marker__'} = 1;
+ }
-use Dancer::Test 'main', 't::lib::Foo';
+ use t::lib::Foo with => { session => engine('session') };
-response_content_like "/main", qr{42}, "session is set in main";
-response_content_like "/in_foo", qr{42}, "... and is also set in Foo app";
+ get '/main' => sub {
+ session('test' => 42);
+ };
-my $engine = t::lib::Foo->dsl->engine('session');
-is $engine->{__marker__}, 1, "the session engine in subapp is the same";
+ setting appdir => $tempdir;
+ Dancer->runner->server->port($port);
+ start;
+ },
+);
done_testing;

0 comments on commit 3c08725

Please sign in to comment.