Mercurial > hg > nginx-tests
comparison http_location.t @ 148:b714d6df958c
Tests: rename some tests for better sorting.
Use underscore instead of dash. Addtionally, rename some tests to better
match "module" + "details" scheme used: use "http_" prefix for http core
module tests, use "mail_" prefix for mail module tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 04 Mar 2011 16:07:15 +0300 |
parents | http-location.t@8ac1faaddd2c |
children | c0ae29632905 |
comparison
equal
deleted
inserted
replaced
147:fd865ada95c8 | 148:b714d6df958c |
---|---|
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(qw/http 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 like(http_get('/t.GIF'), qr/X-Location: regex/, 'regex with mungled case'); | |
80 like(http_get('/casefull/t.gif'), qr/X-Location: regex/, 'first regex wins'); | |
81 like(http_get('/casefull/'), qr/X-Location: casefull/, 'casefull regex'); | |
82 like(http_get('/CASEFULL/'), qr/X-Location: root/, | |
83 'casefull regex do not match wrong case'); | |
84 | |
85 ############################################################################### |