Mercurial > hg > nginx-tests
comparison index.t @ 347:f6d195aa0303
Tests: added tests for index module.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 03 Oct 2013 20:05:57 +0400 |
parents | |
children | e9064d691790 |
comparison
equal
deleted
inserted
replaced
346:c6b1430afc66 | 347:f6d195aa0303 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for index module. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http/)->plan(7) | |
26 ->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
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 add_header X-URI $uri; | |
42 | |
43 location / { | |
44 # index index.html by default | |
45 } | |
46 | |
47 location /redirect/ { | |
48 index /re.html; | |
49 } | |
50 | |
51 location /loop/ { | |
52 index /loop/; | |
53 } | |
54 | |
55 location /no_index/ { | |
56 alias %%TESTDIR%%/; | |
57 index nonexisting.html; | |
58 } | |
59 | |
60 location /many/ { | |
61 alias %%TESTDIR%%/; | |
62 index nonexisting.html many.html; | |
63 } | |
64 | |
65 location /var/ { | |
66 alias %%TESTDIR%%/; | |
67 index $server_name.html; | |
68 } | |
69 | |
70 location /var_redirect/ { | |
71 index /$server_name.html; | |
72 } | |
73 } | |
74 } | |
75 | |
76 EOF | |
77 | |
78 $t->write_file('index.html', 'body'); | |
79 $t->write_file('many.html', 'manybody'); | |
80 $t->write_file('re.html', 'rebody'); | |
81 $t->write_file('localhost.html', 'varbody'); | |
82 | |
83 $t->run(); | |
84 | |
85 ############################################################################### | |
86 | |
87 like(http_get('/'), qr/X-URI: \/index.html.*body/ms, 'default index'); | |
88 like(http_get('/no_index/'), qr/403 Forbidden/, 'no index'); | |
89 like(http_get('/redirect/'), qr/X-URI: \/re.html.*rebody/ms, 'redirect'); | |
90 like(http_get('/loop/'), qr/500 Internal/, 'redirect loop'); | |
91 like(http_get('/many/'), qr/X-URI: \/many\/many.html.*manybody/ms, 'many'); | |
92 like(http_get('/var/'), qr/X-URI: \/var\/localhost.html.*varbody/ms, 'var'); | |
93 like(http_get('/var_redirect/'), qr/X-URI: \/localhost.html.*varbody/ms, | |
94 'var with redirect'); | |
95 | |
96 ############################################################################### |