Mercurial > hg > nginx-tests
comparison http-location.t @ 117:f2b8d86438ee
Tests: add location matching tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 17 Dec 2009 18:41:23 +0300 |
parents | |
children | 18fc08c160ce |
comparison
equal
deleted
inserted
replaced
116:c8341d95297e | 117:f2b8d86438ee |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for location selection. | |
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(8) | |
25 ->write_file_expand('nginx.conf', <<'EOF'); | |
26 | |
27 %%TEST_GLOBALS%% | |
28 | |
29 master_process off; | |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 http { | |
36 %%TEST_GLOBALS_HTTP%% | |
37 | |
38 server { | |
39 listen 127.0.0.1:8080; | |
40 server_name localhost; | |
41 | |
42 location = / { | |
43 add_header X-Location exactlyroot; | |
44 return 204; | |
45 } | |
46 | |
47 location / { | |
48 add_header X-Location root; | |
49 return 204; | |
50 } | |
51 | |
52 location ^~ /images/ { | |
53 add_header X-Location images; | |
54 return 204; | |
55 } | |
56 | |
57 location ~* \.(gif|jpg|jpeg)$ { | |
58 add_header X-Location regex; | |
59 return 204; | |
60 } | |
61 | |
62 location ~ casefull { | |
63 add_header X-Location casefull; | |
64 return 204; | |
65 } | |
66 } | |
67 } | |
68 | |
69 EOF | |
70 | |
71 $t->run(); | |
72 | |
73 ############################################################################### | |
74 | |
75 like(http_get('/'), qr/X-Location: exactlyroot/, 'exactlyroot'); | |
76 like(http_get('/x'), qr/X-Location: root/, 'root'); | |
77 like(http_get('/images/t.gif'), qr/X-Location: images/, 'images'); | |
78 like(http_get('/t.gif'), qr/X-Location: regex/, 'regex'); | |
79 | |
80 { | |
81 local $TODO = 'broken in 0.8.25'; | |
82 | |
83 like(http_get('/t.GIF'), qr/X-Location: regex/, 'regex with mungled case'); | |
84 | |
85 } | |
86 | |
87 like(http_get('/casefull/t.gif'), qr/X-Location: regex/, 'first regex wins'); | |
88 like(http_get('/casefull/'), qr/X-Location: casefull/, 'casefull regex'); | |
89 like(http_get('/CASEFULL/'), qr/X-Location: root/, | |
90 'casefull regex do not match wrong case'); | |
91 | |
92 ############################################################################### |