Mercurial > hg > nginx-tests
annotate http_location.t @ 251:df984d23f9d1
Tests: improve fastcgi keepalive tests.
On some platforms fastcgi_keepalive.t tests failed due to problems in
handling of data split into multiple packets. Harden tests to fail
on all platforms by adding more sleeps, and mark them as TODO till
underlying problems are fixed.
Additionally, add some padding testing.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 25 Jan 2013 20:53:53 +0400 |
parents | 6a0d934950bc |
children | 98c6af2a5138 |
rev | line source |
---|---|
117
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for location selection. |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
121
8ac1faaddd2c
Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents:
119
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(8) |
117
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ->write_file_expand('nginx.conf', <<'EOF'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 %%TEST_GLOBALS%% |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
218
diff
changeset
|
29 daemon off; |
117
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 events { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 http { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 %%TEST_GLOBALS_HTTP%% |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 server { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 listen 127.0.0.1:8080; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 server_name localhost; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 location = / { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 add_header X-Location exactlyroot; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 return 204; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 location / { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 add_header X-Location root; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 return 204; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 location ^~ /images/ { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 add_header X-Location images; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 return 204; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 location ~* \.(gif|jpg|jpeg)$ { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 add_header X-Location regex; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 return 204; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 location ~ casefull { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 add_header X-Location casefull; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 return 204; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 EOF |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 $t->run(); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 ############################################################################### |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 like(http_get('/'), qr/X-Location: exactlyroot/, 'exactlyroot'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 like(http_get('/x'), qr/X-Location: root/, 'root'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 like(http_get('/images/t.gif'), qr/X-Location: images/, 'images'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 like(http_get('/t.gif'), qr/X-Location: regex/, 'regex'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 like(http_get('/t.GIF'), qr/X-Location: regex/, 'regex with mungled case'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 like(http_get('/casefull/t.gif'), qr/X-Location: regex/, 'first regex wins'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 like(http_get('/casefull/'), qr/X-Location: casefull/, 'casefull regex'); |
218
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
81 |
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
82 SKIP: { |
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
83 skip 'caseless os', 1 |
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
84 if $^O eq 'MSWin32' or $^O eq 'darwin'; |
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
85 |
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
86 like(http_get('/CASEFULL/'), qr/X-Location: root/, |
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
87 'casefull regex do not match wrong case'); |
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
88 } |
117
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 ############################################################################### |