Mercurial > hg > nginx-tests
annotate config_dump.t @ 880:697fc80b8606
Tests: added HTTP/2 tests for server_tokens directive.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Wed, 23 Mar 2016 20:37:39 +0300 |
parents | 1dd0e909fe94 |
children | e9064d691790 |
rev | line source |
---|---|
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for dumped nginx configuration (nginx -T). |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 # Among other things, test that configuration blocks are properly processed. |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 ############################################################################### |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use warnings; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 use strict; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 use Test::More; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use lib 'lib'; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http map/); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 plan(skip_all => 'no config dump') unless $t->has_version('1.9.2'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 $t->plan(10)->write_file_expand('nginx.conf', <<'EOF'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 include %%TESTDIR%%/inc.conf; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 events { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 http { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 %%TEST_GLOBALS_HTTP%% |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 map $args $x { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 default 0; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 foo bar; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 include map.conf; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 upstream u { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server 127.0.0.1:8081; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 server { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 listen 127.0.0.1:8080; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 server_name localhost; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 location / { } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 EOF |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 $t->write_file('inc.conf', 'include inc2.conf;'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 $t->write_file('inc2.conf', '#inc2.conf'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 $t->write_file('map.conf', '#map.conf;'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 $t->run(); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 ############################################################################### |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 my $d = $t->testdir; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 my $dump = $t->dump_config(); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 like($dump, qr!^# configuration file $d/nginx.conf:$!m, 'nginx.conf found'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 like($dump, qr!^# configuration file $d/inc.conf:$!m, 'inc.conf found'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 like($dump, qr!^# configuration file $d/inc2.conf:$!m, 'inc2.conf found'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 like($dump, qr!^# configuration file $d/map.conf:$!m, 'map.conf found'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 is(getconf($t, $dump, 'nginx.conf'), $t->read_file('nginx.conf'), 'content'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 is(getconf($t, $dump, 'inc.conf'), $t->read_file('inc.conf'), 'content inc'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 is(getconf($t, $dump, 'map.conf'), $t->read_file('map.conf'), 'content inc 2'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 unlink($t->testdir . "/inc.conf"); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 unlink($t->testdir . "/map.conf"); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 $dump = $t->dump_config(); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 unlike($dump, qr!file $d/inc.conf!, 'missing inc.conf'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 unlike($dump, qr!file $d/map.conf!, 'missing map.conf'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 like($dump, qr!file $d/nginx.conf test failed!, 'test failed'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 $t->write_file('inc.conf', 'include inc2.conf;'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 $t->write_file('inc2.conf', '#inc2.conf'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 $t->write_file('map.conf', '#map.conf;'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 ############################################################################### |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 sub getconf { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 my ($t, $string, $conf) = @_; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 my $prefix = "# configuration file $d/$conf:\n"; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 my $offset = index($string, $prefix) + length($prefix); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 my $len = length($t->read_file($conf)); |
624
1dd0e909fe94
Tests: compatibility with perl <= 5.12 in config_dump.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
621
diff
changeset
|
103 my $s = substr($string, $offset, $len); |
1dd0e909fe94
Tests: compatibility with perl <= 5.12 in config_dump.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
621
diff
changeset
|
104 $s =~ tr/\r//d; |
1dd0e909fe94
Tests: compatibility with perl <= 5.12 in config_dump.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
621
diff
changeset
|
105 return $s; |
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 } |