Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More import => ['!pass']; | ||
|
||
BEGIN { | ||
use Dancer::ModuleLoader; | ||
|
||
plan skip_all => "LWP::UserAgent is needed to run this tests" | ||
unless Dancer::ModuleLoader->load('LWP::UserAgent'); | ||
plan skip_all => 'Test::TCP is needed to run this test' | ||
unless Dancer::ModuleLoader->load('Test::TCP'); | ||
plan skip_all => 'JSON is needed to run this test' | ||
unless Dancer::ModuleLoader->load('JSON'); | ||
plan skip_all => 'HTTP::Request is needed to run this test' | ||
unless Dancer::ModuleLoader->load('HTTP::Request'); | ||
} | ||
|
||
plan tests => 6; | ||
|
||
use Dancer; | ||
|
||
Test::TCP::test_tcp( | ||
client => sub { | ||
my $port = shift; | ||
my $url = "http://127.0.0.1:$port/"; | ||
my $req = HTTP::Request->new( GET => $url ); | ||
$req->header( 'Content-Type' => 'application/json' ); | ||
my $ua = LWP::UserAgent->new; | ||
ok my $res = $ua->request($req); | ||
is $res->code, 200; | ||
is_deeply(JSON::decode_json($res->content), {foo => 1}); | ||
}, | ||
server => sub { | ||
my $port = shift; | ||
load_app 't::lib::TestSerializer'; | ||
setting access_log => 0; | ||
setting port => $port; | ||
Dancer->dance(); | ||
} | ||
); | ||
|
||
Test::TCP::test_tcp( | ||
client => sub { | ||
my $port = shift; | ||
my $url = "http://127.0.0.1:$port/blessed"; | ||
my $req = HTTP::Request->new( GET => $url ); | ||
$req->header( 'Content-Type' => 'application/json' ); | ||
my $ua = LWP::UserAgent->new; | ||
ok my $res = $ua->request($req); | ||
is $res->code, 200; | ||
is_deeply( JSON::decode_json( $res->content ), { request => undef } ); | ||
}, | ||
server => sub { | ||
my $port = shift; | ||
load_app 't::lib::TestSerializer'; | ||
setting access_log => 0; | ||
setting port => $port; | ||
setting engines => | ||
{ JSON => { allow_blessed => 1, convert_blessed => 1 } }; | ||
Dancer->dance(); | ||
} | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters