-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/set-apphandler'
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 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
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
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,34 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
use Test::More tests => 5; | ||
use LWP::UserAgent; | ||
|
||
eval "use LWP::Protocol::PSGI"; | ||
plan skip_all => "LWP::Protocol::PSGI is needed for this test" if $@; | ||
|
||
my $psgi_app = do { | ||
use Dancer2; | ||
|
||
set apphandler => 'PSGI'; | ||
|
||
get '/search' => sub { | ||
my $q = param('q'); | ||
is( $q, 'foo', 'Correct parameter to Google' ); | ||
return 'bar'; | ||
}; | ||
|
||
dance; | ||
}; | ||
|
||
# Register the $psgi_app to handle all LWP requests | ||
LWP::Protocol::PSGI->register($psgi_app); | ||
my $ua = LWP::UserAgent->new; | ||
isa_ok( $ua, 'LWP::UserAgent' ); | ||
|
||
my $res = $ua->get("http://www.google.com/search?q=foo"); | ||
isa_ok( $res, 'HTTP::Response' ); | ||
|
||
ok( $res->is_success, 'Request is successful' ); | ||
is( $res->content, 'bar', 'Correct response content' ); | ||
|