annotate http-location.t @ 144:6e11354cae8a

Tests: rework stopping to make "open socket left" alerts visible. Use SIGQUIT to stop nginx to make sure relevant checks are executed. Use separate functions to stop nginx and daemons to make it possible to stop nginx before daemons.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 15 Dec 2010 19:22:39 +0300
parents 8ac1faaddd2c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
117
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for location selection.
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use lib 'lib';
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use Test::Nginx;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 ###############################################################################
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 select STDERR; $| = 1;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDOUT; $| = 1;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 119
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(8)
117
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 %%TEST_GLOBALS%%
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
29 master_process off;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30 daemon off;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32 events {
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33 }
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35 http {
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38 server {
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 listen 127.0.0.1:8080;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40 server_name localhost;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42 location = / {
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 add_header X-Location exactlyroot;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 return 204;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45 }
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 location / {
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 add_header X-Location root;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 return 204;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50 }
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52 location ^~ /images/ {
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 add_header X-Location images;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54 return 204;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 }
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57 location ~* \.(gif|jpg|jpeg)$ {
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 add_header X-Location regex;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 return 204;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 }
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 location ~ casefull {
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63 add_header X-Location casefull;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 return 204;
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65 }
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 }
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 }
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 EOF
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71 $t->run();
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73 ###############################################################################
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
75 like(http_get('/'), qr/X-Location: exactlyroot/, 'exactlyroot');
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76 like(http_get('/x'), qr/X-Location: root/, 'root');
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
77 like(http_get('/images/t.gif'), qr/X-Location: images/, 'images');
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
78 like(http_get('/t.gif'), qr/X-Location: regex/, 'regex');
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79 like(http_get('/t.GIF'), qr/X-Location: regex/, 'regex with mungled case');
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80 like(http_get('/casefull/t.gif'), qr/X-Location: regex/, 'first regex wins');
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
81 like(http_get('/casefull/'), qr/X-Location: casefull/, 'casefull regex');
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
82 like(http_get('/CASEFULL/'), qr/X-Location: root/,
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
83 'casefull regex do not match wrong case');
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
84
f2b8d86438ee Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
85 ###############################################################################