annotate config_dump.t @ 1020:196d33c2bb45

Tests: removed TODO and try_run() checks for legacy versions. Also removed now unused spdy.t and shmem prerequisite.
author Andrey Zelenkov <zelenkov@nginx.com>
date Wed, 31 Aug 2016 18:21:07 +0300
parents 882267679006
children a07205e8bb76
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 $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
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;
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 events {
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
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 http {
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 %%TEST_GLOBALS_HTTP%%
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 map $args $x {
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 default 0;
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 foo bar;
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 include map.conf;
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 }
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 upstream u {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
49 server 127.0.0.1:8081;
621
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 }
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
53 listen 127.0.0.1:8080;
621
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 server_name localhost;
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 location / { }
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 }
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 EOF
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 $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
63 $t->write_file('inc2.conf', '#inc2.conf');
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 $t->write_file('map.conf', '#map.conf;');
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 $t->run();
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 ###############################################################################
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 my $d = $t->testdir;
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 $dump = $t->dump_config();
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 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
74 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
75 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
76 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
77
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 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
79 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
80 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
81
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 unlink($t->testdir . "/inc.conf");
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 unlink($t->testdir . "/map.conf");
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 $dump = $t->dump_config();
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 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
87 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
88 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
89
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 $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
91 $t->write_file('inc2.conf', '#inc2.conf');
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 $t->write_file('map.conf', '#map.conf;');
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 ###############################################################################
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 sub getconf {
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 my ($t, $string, $conf) = @_;
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 my $prefix = "# configuration file $d/$conf:\n";
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 my $offset = index($string, $prefix) + length($prefix);
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 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
101 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
102 $s =~ tr/\r//d;
1dd0e909fe94 Tests: compatibility with perl <= 5.12 in config_dump.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 621
diff changeset
103 return $s;
621
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 }