Mercurial > hg > nginx-tests
annotate mirror.t @ 1542:451e787aad76
Tests: reworked libgd version detection.
The "libgd-config" binary is deprecated in recent versions and may not exist
or have unexpected output. More, it may not present within older versions,
as well, if installed separately, which previously broke test assumptions.
The fix is change the fallback to skip tests. In addition, recent Perl GD
module (2.57) started to export libgd version, which is now also consulted.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 13 Jan 2020 18:15:35 +0300 |
parents | 97c8280de681 |
children |
rev | line source |
---|---|
1208
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for http mirror module. |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1208
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http mirror/)->plan(8); |
1208
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 log_format test $uri; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server_name localhost; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 location / { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 mirror /mirror; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location /off { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 mirror off; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 location /many { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 mirror /mirror/1; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 mirror /mirror/2; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 location /mirror { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 log_subrequest on; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 access_log test$args.log test; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 EOF |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 $t->write_file('index.html', ''); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 $t->write_file('many', ''); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 $t->write_file('off', ''); |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1208
diff
changeset
|
70 $t->run(); |
1208
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 ############################################################################### |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 like(http_get('/index.html?1'), qr/200 OK/, 'request'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 like(http_get('/?2'), qr/200 OK/, 'internal redirect'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 like(http_get('/off?3'), qr/200 OK/, 'mirror off'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 like(http_get('/many?4'), qr/200 OK/, 'mirror many'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 $t->stop(); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 is($t->read_file('test1.log'), "/mirror\n", 'log - request'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 is($t->read_file('test2.log'), "/mirror\n/mirror\n", 'log - redirect'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 ok(!-e $t->testdir() . '/test3.log', 'log - mirror off'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 is($t->read_file('test4.log'), "/mirror/1\n/mirror/2\n", 'log - mirror many'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 ############################################################################### |