Created
August 12, 2011 16:06
-
-
Save memememomo/1142366 to your computer and use it in GitHub Desktop.
CGI Plack Test
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
use strict; | |
use warnings; | |
use Test::More; | |
use Plack::Test; | |
use HTTP::Request::Common; | |
use Plack::Loader; | |
use Plack::Util (); | |
my $app = Plack::Util::load_psgi('app.psgi'); | |
test_psgi $app, sub { | |
my $cb = shift; | |
my $res; | |
$res = $cb->(GET "/index.cgi"); | |
is $res->code, '200'; | |
$res = $cb->(GET "/hello.cgi?name=memememomo"); | |
is $res->content, "Hello, memememomo"; | |
$res = $cb->(POST '/post.cgi', { name => 'memememomo' }); | |
is $res->content, "Hello, memememomo"; | |
$res = $cb->(GET '/redirect.cgi'); | |
is $res->code, '301'; | |
}; | |
done_testing(); |
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
use strict; | |
use warnings; | |
use Plack::Test; | |
use Plack::Util; | |
use Test::More; | |
use Test::Requires 'Test::WWW::Mechanize::PSGI'; | |
my $app = Plack::Util::load_psgi 'app.psgi'; | |
my $mech = Test::WWW::Mechanize::PSGI->new(app => $app); | |
$mech->get_ok('/index.cgi'); | |
$mech->get_ok('/hello.cgi?name=memememomo'); | |
$mech->content_like(qr/Hello, memememomo/); | |
$mech->post_ok('/post.cgi', { name => 'memememomo' }); | |
$mech->content_like(qr/Hello, memememomo/); | |
$mech->get_ok('/redirect.cgi'); | |
done_testing; |
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use File::Basename; | |
use Plack::Builder; | |
use Plack::App::CGIBin; | |
my $basedir = dirname(__FILE__); | |
builder { | |
mount "/" => | |
Plack::App::CGIBin->new( root => $basedir, exec_cb => sub { 1 } )->to_app; | |
}; |
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use CGI; | |
my $q = CGI->new; | |
my $name = $q->param('name'); | |
$q->header(-type => 'text/plain'); | |
print "Hello, $name"; |
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use CGI; | |
my $q = CGI->new; | |
$q->header(-type => 'text/plain'); | |
print "ok"; |
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use CGI; | |
my $q = CGI->new; | |
my $name = $q->param('name'); | |
print $q->header(-type => 'text/plain'); | |
print "Hello, $name"; |
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use CGI; | |
my $q = CGI->new; | |
print $q->redirect( | |
-status => 301, | |
-uri => '/index.cgi' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment