]> git.donarmstrong.com Git - debbugs.git/blob - t/17_version_cgi.t
add test for version.cgi cache control
[debbugs.git] / t / 17_version_cgi.t
1 # -*- mode: cperl;-*-
2
3 use Test::More;
4
5 use warnings;
6 use strict;
7
8 plan tests => 2;
9
10 my $port = 11343;
11
12 our $child_pid = undef;
13
14 END{
15      if (defined $child_pid) {
16           my $temp_exit = $?;
17           kill(15,$child_pid);
18           waitpid(-1,0);
19           $? = $temp_exit;
20      }
21 }
22
23 my $pid = fork;
24 die "Unable to fork child" if not defined $pid;
25 if ($pid) {
26      $child_pid = $pid;
27      # Wait for two seconds to let the child start
28      sleep 2;
29 }
30 else {
31     # UGH.
32     package SillyWebServer;
33     use HTTP::Server::Simple;
34     use base qw(HTTP::Server::Simple::CGI::Environment HTTP::Server::Simple);
35     sub handler {
36         my $fh;
37         open($fh,'-|',-e './cgi/version.cgi'? './cgi/version.cgi' : '../cgi/version.cgi');
38         my $headers;
39         my $status = 200;
40         while (<$fh>) {
41             if (/^\s*$/ and $status) {
42                 print "HTTP/1.1 $status OK\n";
43                 print $headers;
44                 $status = 0;
45                 print $_;
46             } elsif ($status) {
47                 $headers .= $_;
48                 if (/^Status:\s*(\d+)/i) {
49                     $status = $1;
50                 }
51             } else {
52                 print $_;
53             }
54
55         }
56      }
57     my $server = SillyWebServer->new($port);
58     $server->run();
59     exit 0;
60 }
61
62
63 use LWP::UserAgent;
64 my $ua = LWP::UserAgent->new;
65 $ua->agent("DebbugsTesting/0.1 ");
66
67 # Create a request
68 my $req = HTTP::Request->new(GET => "http://localhost:$port/");
69
70 my $res = $ua->request($req);
71 ok($res->is_success(),'cgi/version.cgi returns success');
72 my $etag = $res->header('Etag');
73
74 $req = HTTP::Request->new(GET => "http://localhost:$port/",['If-None-Match',$etag]);
75 $res = $ua->request($req);
76 ok($res->code() eq '304','If-None-Match set gives us 304 not modified');
77
78
79