]> git.donarmstrong.com Git - debbugs.git/blob - t/18_libravatar_cgi.t
abstract out create config in tests
[debbugs.git] / t / 18_libravatar_cgi.t
1 # -*- mode: cperl;-*-
2
3 use warnings;
4 use strict;
5
6 use Test::More;
7 # The test functions are placed here to make things easier
8 use lib qw(t/lib);
9 use DebbugsTest qw(:all);
10
11 plan tests => 3;
12
13 my $port = 11344;
14
15 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
16 $SIG{CHLD} = sub {};
17 our %config;
18 eval {
19     %config = create_debbugs_configuration();
20 };
21 if ($@) {
22      BAIL_OUT($@);
23  }
24 $ENV{DEBBUGS_CONFIG_FILE}  = "$config{config_dir}/debbugs_config";
25
26 my $libravatar_cgi_handler = sub {
27     my $fh;
28     $ENV{DEBBUGS_CONFIG_FILE} = $config{config_dir}."/debbugs_config";
29     open($fh,'-|',-e './cgi/libravatar.cgi'? './cgi/libravatar.cgi'
30          : '../cgi/libravatar.cgi');
31     my $headers;
32     my $status = 200;
33     while (<$fh>) {
34         if (/^\s*$/ and $status) {
35             print "HTTP/1.1 $status OK\n";
36             print $headers;
37             $status = 0;
38             print $_;
39         } elsif ($status) {
40             $headers .= $_;
41             if (/^Status:\s*(\d+)/i) {
42                 $status = $1;
43             }
44         } else {
45             print $_;
46         }
47     }
48 };
49
50
51 ok(DebbugsTest::HTTPServer::fork_and_create_webserver($libravatar_cgi_handler,$port),
52    'forked HTTP::Server::Simple successfully');
53
54 use LWP::UserAgent;
55 my $ua = LWP::UserAgent->new;
56 $ua->agent("DebbugsTesting/0.1 ");
57
58 # Create a request
59 my $req = HTTP::Request->new(GET => "http://localhost:$port/?avatar=no");
60
61 my $res = $ua->request($req);
62 ok($res->is_success(),'cgi/libravatar.cgi returns success');
63 my $etag = $res->header('Etag');
64
65 $req = HTTP::Request->new(GET => "http://localhost:$port/?avatar=no",
66                           ['If-None-Match',$etag]);
67 $res = $ua->request($req);
68 ok($res->code() eq '304','If-None-Match set gives us 304 not modified');
69
70
71