Mercurial > hg > nginx-tests
comparison mirror.t @ 1208:a6453cf5786a
Tests: http mirror module tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 11 Aug 2017 19:01:44 +0300 |
parents | |
children | 97c8280de681 |
comparison
equal
deleted
inserted
replaced
1207:b1dc56ad15e9 | 1208:a6453cf5786a |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for http mirror module. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http mirror/); | |
26 | |
27 $t->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 log_format test $uri; | |
40 | |
41 server { | |
42 listen 127.0.0.1:8080; | |
43 server_name localhost; | |
44 | |
45 location / { | |
46 mirror /mirror; | |
47 | |
48 location /off { | |
49 mirror off; | |
50 } | |
51 } | |
52 | |
53 location /many { | |
54 mirror /mirror/1; | |
55 mirror /mirror/2; | |
56 } | |
57 | |
58 location /mirror { | |
59 log_subrequest on; | |
60 access_log test$args.log test; | |
61 } | |
62 } | |
63 } | |
64 | |
65 EOF | |
66 | |
67 $t->write_file('index.html', ''); | |
68 $t->write_file('many', ''); | |
69 $t->write_file('off', ''); | |
70 $t->try_run('no mirror')->plan(8); | |
71 | |
72 ############################################################################### | |
73 | |
74 like(http_get('/index.html?1'), qr/200 OK/, 'request'); | |
75 like(http_get('/?2'), qr/200 OK/, 'internal redirect'); | |
76 like(http_get('/off?3'), qr/200 OK/, 'mirror off'); | |
77 like(http_get('/many?4'), qr/200 OK/, 'mirror many'); | |
78 | |
79 $t->stop(); | |
80 | |
81 is($t->read_file('test1.log'), "/mirror\n", 'log - request'); | |
82 is($t->read_file('test2.log'), "/mirror\n/mirror\n", 'log - redirect'); | |
83 ok(!-e $t->testdir() . '/test3.log', 'log - mirror off'); | |
84 is($t->read_file('test4.log'), "/mirror/1\n/mirror/2\n", 'log - mirror many'); | |
85 | |
86 ############################################################################### |