[PATCH] http_try_files.t: extend test coverage

Damien Tournoud damien at commerceguys.com
Tue Jan 20 23:57:53 UTC 2015


# HG changeset patch
# User Damien Tournoud <damien at commerceguys.com>
# Date 1421798229 -3600
#      Wed Jan 21 00:57:09 2015 +0100
# Node ID b99eb5bef46a7b7d9e7bcd32967041d287c80fdb
# Parent  4bcf8bc2bafe1515154e60710ea6ae674080b26c
http_try_files.t: extend test coverage

This extends the test coverage for all the cases of files
or directories matched against each other.

The test case "file doesn't match dir" currently fails,
fixed in http://mailman.nginx.org/pipermail/nginx-devel/2015-January/006468.html

diff -r 4bcf8bc2bafe -r b99eb5bef46a http_try_files.t
--- a/http_try_files.t	Thu Jan 15 18:23:16 2015 +0300
+++ b/http_try_files.t	Wed Jan 21 00:57:09 2015 +0100
@@ -21,7 +21,7 @@
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(4)
+my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(8)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -50,6 +50,22 @@
             try_files /short $uri =404;
         }
 
+        location /file-file/ {
+            try_files /found.html =404;
+        }
+
+        location /file-dir/ {
+            try_files /found.html/ =404;
+        }
+
+        location /dir-dir/ {
+            try_files /directory/ =404;
+        }
+
+        location /dir-file/ {
+            try_files /directory =404;
+        }
+
         location /fallback {
             proxy_pass http://127.0.0.1:8081/fallback;
         }
@@ -72,6 +88,7 @@
 EOF
 
 $t->write_file('found.html', 'SEE THIS');
+mkdir $t->{_testdir} . '/directory';
 $t->run();
 
 ###############################################################################
@@ -80,5 +97,9 @@
 like(http_get('/uri/notfound'), qr!X-URI: /fallback!, 'not found uri');
 like(http_get('/nouri/notfound'), qr!X-URI: /fallback!, 'not found nouri');
 like(http_get('/short/long'), qr!404 Not!, 'short uri in try_files');
+like(http_get('/file-file/'), qr!SEE THIS!, 'file matches file');
+like(http_get('/file-dir/'), qr!404 Not!, 'file doesn\'t match dir');
+like(http_get('/dir-dir/'), qr!301 Moved Permanently!, 'dir matches dir');
+like(http_get('/dir-file/'), qr!404 Not!, 'dir doesn\'t match file');
 
 ###############################################################################



More information about the nginx-devel mailing list