Mercurial > hg > nginx-tests
annotate config_dump.t @ 1248:70192b1baf01
Tests: added exception test to stream_js.t using 'require'.
The stream js tests introduced in edf5a3c9e36a fail on njs 0.1.14. It doesn't
currently provide an easy way to check its version, whilst we are obligated to
gracefully handle such cases somehow. With such an addition of 'require', now
the tests are skipped instead on the previous versions.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 21 Nov 2017 13:16:39 +0300 |
parents | a07205e8bb76 |
children | 766bcbb632ee |
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 |
1060
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
28 $t->plan(13)->write_file_expand('nginx.conf', <<'EOF'); |
621
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 %%TEST_GLOBALS%% |
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 daemon off; |
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 include %%TESTDIR%%/inc.conf; |
1060
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
35 include %%TESTDIR%%/inc.conf; |
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 events { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 } |
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 http { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 %%TEST_GLOBALS_HTTP%% |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 map $args $x { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 default 0; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 foo bar; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 include map.conf; |
1060
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
47 include map.conf; |
621
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 { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
51 server 127.0.0.1:8081; |
621
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 { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
55 listen 127.0.0.1:8080; |
621
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 |
1060
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
80 TODO: { |
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
81 local $TODO = 'not yet' unless $t->has_version('1.11.6'); |
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
82 |
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
83 unlike($dump, qr!(# configuration file $d/inc.conf:).*\1!s, 'inc.conf uniq'); |
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
84 unlike($dump, qr!(# configuration file $d/inc2.conf:).*\1!s, 'inc2.conf uniq'); |
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
85 unlike($dump, qr!(# configuration file $d/map.conf:).*\1!s, 'map.conf uniq'); |
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
86 |
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
87 } |
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
88 |
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 unlink($t->testdir . "/inc.conf"); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 unlink($t->testdir . "/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 $dump = $t->dump_config(); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 $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
|
102 $t->write_file('inc2.conf', '#inc2.conf'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 $t->write_file('map.conf', '#map.conf;'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 ############################################################################### |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 sub getconf { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 my ($t, $string, $conf) = @_; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 my $prefix = "# configuration file $d/$conf:\n"; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 my $offset = index($string, $prefix) + length($prefix); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 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
|
112 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
|
113 $s =~ tr/\r//d; |
1dd0e909fe94
Tests: compatibility with perl <= 5.12 in config_dump.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
621
diff
changeset
|
114 return $s; |
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 } |