comparison rewrite.t @ 65:02b82337a3ec

Tests: some rewrite tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 26 Jan 2009 17:54:49 +0300
parents
children b9bf423929cc
comparison
equal deleted inserted replaced
64:726c3c2a8b8c 65:02b82337a3ec
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for rewrite module.
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('rewrite')->plan(5)
25 ->write_file_expand('nginx.conf', <<'EOF');
26
27 master_process off;
28 daemon off;
29
30 events {
31 }
32
33 http {
34 access_log off;
35
36 client_body_temp_path %%TESTDIR%%/client_body_temp;
37 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp;
38 proxy_temp_path %%TESTDIR%%/proxy_temp;
39
40 server {
41 listen 127.0.0.1:8080;
42 server_name localhost;
43
44 location / {
45 rewrite ^ http://example.com/ redirect;
46 }
47
48 location /add {
49 rewrite ^ http://example.com/?c=d redirect;
50 }
51
52 location /no {
53 rewrite ^ http://example.com/?c=d? redirect;
54 }
55 }
56 }
57
58 EOF
59
60 $t->run();
61
62 ###############################################################################
63
64 like(http_get('/'), qr!^Location: http://example.com/\x0d?$!ms, 'simple');
65 like(http_get('/?a=b'), qr!^Location: http://example.com/\?a=b\x0d?$!ms,
66 'simple with args');
67 like(http_get('/add'), qr!^Location: http://example.com/\?c=d\x0d?$!ms,
68 'add args');
69
70 TODO: {
71 local $TODO = 'broken since 0.1.18';
72
73 like(http_get('/add?a=b'), qr!^Location: http://example.com/\?c=d&a=b\x0d?$!ms,
74 'add args with args');
75
76 }
77
78 like(http_get('/no?a=b'), qr!^Location: http://example.com/\?c=d\x0d?$!ms,
79 'no args with args');
80
81 ###############################################################################