X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=t%2F17_version_cgi.t;fp=t%2F17_version_cgi.t;h=35d75c4c20b5e5a901244469d807f107a80bf101;hb=426fe0ee1b5fc70e19769f872922e99d72ed5d89;hp=0000000000000000000000000000000000000000;hpb=439cc3070c8396865639bacbf98704cae68a24bd;p=debbugs.git diff --git a/t/17_version_cgi.t b/t/17_version_cgi.t new file mode 100644 index 0000000..35d75c4 --- /dev/null +++ b/t/17_version_cgi.t @@ -0,0 +1,79 @@ +# -*- mode: cperl;-*- + +use Test::More; + +use warnings; +use strict; + +plan tests => 2; + +my $port = 11343; + +our $child_pid = undef; + +END{ + if (defined $child_pid) { + my $temp_exit = $?; + kill(15,$child_pid); + waitpid(-1,0); + $? = $temp_exit; + } +} + +my $pid = fork; +die "Unable to fork child" if not defined $pid; +if ($pid) { + $child_pid = $pid; + # Wait for two seconds to let the child start + sleep 2; +} +else { + # UGH. + package SillyWebServer; + use HTTP::Server::Simple; + use base qw(HTTP::Server::Simple::CGI::Environment HTTP::Server::Simple); + sub handler { + my $fh; + open($fh,'-|',-e './cgi/version.cgi'? './cgi/version.cgi' : '../cgi/version.cgi'); + my $headers; + my $status = 200; + while (<$fh>) { + if (/^\s*$/ and $status) { + print "HTTP/1.1 $status OK\n"; + print $headers; + $status = 0; + print $_; + } elsif ($status) { + $headers .= $_; + if (/^Status:\s*(\d+)/i) { + $status = $1; + } + } else { + print $_; + } + + } + } + my $server = SillyWebServer->new($port); + $server->run(); + exit 0; +} + + +use LWP::UserAgent; +my $ua = LWP::UserAgent->new; +$ua->agent("DebbugsTesting/0.1 "); + +# Create a request +my $req = HTTP::Request->new(GET => "http://localhost:$port/"); + +my $res = $ua->request($req); +ok($res->is_success(),'cgi/version.cgi returns success'); +my $etag = $res->header('Etag'); + +$req = HTTP::Request->new(GET => "http://localhost:$port/",['If-None-Match',$etag]); +$res = $ua->request($req); +ok($res->code() eq '304','If-None-Match set gives us 304 not modified'); + + +