Mercurial > hg > nginx-tests
annotate rewrite.t @ 114:44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
With test config nginx will fail to start as of 0.8.28 due to incorrect
conversion of regular expressions to lowercase. Patch was discussed on
mailing list and will be included in next release.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 30 Nov 2009 14:47:17 +0300 |
parents | 1c0ec30614c6 |
children | 8ac1faaddd2c |
rev | line source |
---|---|
65 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for rewrite module. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
24 my $t = Test::Nginx->new()->has('rewrite')->plan(5) | |
25 ->write_file_expand('nginx.conf', <<'EOF'); | |
26 | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
70
diff
changeset
|
27 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
70
diff
changeset
|
28 |
65 | 29 master_process off; |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 http { | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
70
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
65 | 37 |
38 server { | |
39 listen 127.0.0.1:8080; | |
40 server_name localhost; | |
41 | |
42 location / { | |
43 rewrite ^ http://example.com/ redirect; | |
44 } | |
45 | |
46 location /add { | |
47 rewrite ^ http://example.com/?c=d redirect; | |
48 } | |
49 | |
50 location /no { | |
51 rewrite ^ http://example.com/?c=d? redirect; | |
52 } | |
53 } | |
54 } | |
55 | |
56 EOF | |
57 | |
58 $t->run(); | |
59 | |
60 ############################################################################### | |
61 | |
62 like(http_get('/'), qr!^Location: http://example.com/\x0d?$!ms, 'simple'); | |
63 like(http_get('/?a=b'), qr!^Location: http://example.com/\?a=b\x0d?$!ms, | |
64 'simple with args'); | |
65 like(http_get('/add'), qr!^Location: http://example.com/\?c=d\x0d?$!ms, | |
66 'add args'); | |
67 | |
68 like(http_get('/add?a=b'), qr!^Location: http://example.com/\?c=d&a=b\x0d?$!ms, | |
69 'add args with args'); | |
70 | |
71 like(http_get('/no?a=b'), qr!^Location: http://example.com/\?c=d\x0d?$!ms, | |
72 'no args with args'); | |
73 | |
74 ############################################################################### |