comparison debug_connection.t @ 301:a107552ac714

Tests: added tests for debug_connection.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 28 Jun 2013 16:39:12 +0400
parents
children ad51e58c2d7a
comparison
equal deleted inserted replaced
300:d753dfcaa419 301:a107552ac714
1 #!/usr/bin/perl
2
3 # (C) Nginx, Inc
4
5 # Tests for debug_connection.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
15
16 use lib 'lib';
17 use Test::Nginx;
18
19 ###############################################################################
20
21 select STDERR; $| = 1;
22 select STDOUT; $| = 1;
23
24 my $t = Test::Nginx->new()->has(qw/http --with-debug ipv6 proxy/);
25
26 plan(skip_all => 'not yet') unless $t->has_version('1.5.2');
27
28 $t->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 daemon off;
33
34 events {
35 debug_connection ::1;
36 }
37
38 http {
39 %%TEST_GLOBALS_HTTP%%
40
41 error_log %%TESTDIR%%/debug1.log alert;
42 error_log %%TESTDIR%%/debug2.log alert;
43
44 server {
45 listen 127.0.0.1:8080;
46 listen [::1]:8080;
47 server_name localhost;
48
49 location /debug {
50 proxy_pass http://[::1]:8080/;
51 }
52 }
53 }
54
55 EOF
56
57 eval {
58 open OLDERR, ">&", \*STDERR; close STDERR;
59 $t->run();
60 open STDERR, ">&", \*OLDERR;
61 };
62 plan(skip_all => 'no inet6 support') if $@;
63
64 $t->plan(5);
65
66 ###############################################################################
67
68 my $d = $t->testdir();
69
70 http_get('/');
71 is(read_file("$d/debug1.log"), '', 'no debug_connection file 1');
72 is(read_file("$d/debug2.log"), '', 'no debug_connection file 1');
73
74 http_get('/debug');
75 like(read_file("$d/debug1.log"), qr/\[debug\]/, 'debug_connection file 1');
76 like(read_file("$d/debug2.log"), qr/\[debug\]/, 'debug_connection file 2');
77 is(read_file("$d/debug1.log"), read_file("$d/debug2.log"),
78 'debug_connection file1 file2 match');
79
80 ###############################################################################
81
82 sub read_file {
83 my ($file) = shift;
84 open my $fh, '<', $file or return "$!";
85 local $/;
86 my $content = <$fh>;
87 close $fh;
88 return $content;
89 }
90
91 ###############################################################################