Mercurial > hg > nginx-tests
comparison http_try_files.t @ 523:64eabe6aa1f2
Tests: try_files tests for files and directory matching.
author | Damien Tournoud <damien@commerceguys.com> |
---|---|
date | Wed, 21 Jan 2015 00:57:09 +0100 |
parents | 25f2ba615000 |
children | 907e89fba9c3 |
comparison
equal
deleted
inserted
replaced
522:5b5ef52d6fd2 | 523:64eabe6aa1f2 |
---|---|
19 ############################################################################### | 19 ############################################################################### |
20 | 20 |
21 select STDERR; $| = 1; | 21 select STDERR; $| = 1; |
22 select STDOUT; $| = 1; | 22 select STDOUT; $| = 1; |
23 | 23 |
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(4) | 24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(8) |
25 ->write_file_expand('nginx.conf', <<'EOF'); | 25 ->write_file_expand('nginx.conf', <<'EOF'); |
26 | 26 |
27 %%TEST_GLOBALS%% | 27 %%TEST_GLOBALS%% |
28 | 28 |
29 daemon off; | 29 daemon off; |
48 | 48 |
49 location /short/ { | 49 location /short/ { |
50 try_files /short $uri =404; | 50 try_files /short $uri =404; |
51 } | 51 } |
52 | 52 |
53 location /file-file/ { | |
54 try_files /found.html =404; | |
55 } | |
56 | |
57 location /file-dir/ { | |
58 try_files /found.html/ =404; | |
59 } | |
60 | |
61 location /dir-dir/ { | |
62 try_files /directory/ =404; | |
63 } | |
64 | |
65 location /dir-file/ { | |
66 try_files /directory =404; | |
67 } | |
68 | |
53 location /fallback { | 69 location /fallback { |
54 proxy_pass http://127.0.0.1:8081/fallback; | 70 proxy_pass http://127.0.0.1:8081/fallback; |
55 } | 71 } |
56 location /fallback_nouri { | 72 location /fallback_nouri { |
57 proxy_pass http://127.0.0.1:8081; | 73 proxy_pass http://127.0.0.1:8081; |
69 } | 85 } |
70 } | 86 } |
71 | 87 |
72 EOF | 88 EOF |
73 | 89 |
90 mkdir($t->testdir() . '/directory'); | |
74 $t->write_file('found.html', 'SEE THIS'); | 91 $t->write_file('found.html', 'SEE THIS'); |
75 $t->run(); | 92 $t->run(); |
76 | 93 |
77 ############################################################################### | 94 ############################################################################### |
78 | 95 |
79 like(http_get('/found.html'), qr!SEE THIS!, 'found'); | 96 like(http_get('/found.html'), qr!SEE THIS!, 'found'); |
80 like(http_get('/uri/notfound'), qr!X-URI: /fallback!, 'not found uri'); | 97 like(http_get('/uri/notfound'), qr!X-URI: /fallback!, 'not found uri'); |
81 like(http_get('/nouri/notfound'), qr!X-URI: /fallback!, 'not found nouri'); | 98 like(http_get('/nouri/notfound'), qr!X-URI: /fallback!, 'not found nouri'); |
82 like(http_get('/short/long'), qr!404 Not!, 'short uri in try_files'); | 99 like(http_get('/short/long'), qr!404 Not!, 'short uri in try_files'); |
83 | 100 |
101 like(http_get('/file-file/'), qr!SEE THIS!, 'file matches file'); | |
102 | |
103 TODO: { | |
104 local $TODO = 'not yet' unless $t->has_version('1.7.10'); | |
105 | |
106 like(http_get('/file-dir/'), qr!404 Not!, 'file does not match dir'); | |
107 | |
108 } | |
109 | |
110 like(http_get('/dir-dir/'), qr!301 Moved Permanently!, 'dir matches dir'); | |
111 like(http_get('/dir-file/'), qr!404 Not!, 'dir does not match file'); | |
112 | |
84 ############################################################################### | 113 ############################################################################### |