comparison map.t @ 227:16371849bd07

Tests: map module basic tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 29 Jun 2012 02:00:55 +0400
parents
children a01a53bcbf11
comparison
equal deleted inserted replaced
226:e7a01be387ad 227:16371849bd07
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for map 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(qw/http map/)->plan(5);
25
26 $t->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 map $args $x {
39 default 0;
40 foo bar;
41 }
42
43 map $args $y {
44 hostnames;
45 default 0;
46 example.com foo;
47 example.* wildcard;
48 }
49
50 server {
51 listen 127.0.0.1:8080;
52 server_name localhost;
53
54 location / {
55 add_header X-Foo "x:$x y:$y\n";
56 }
57 }
58 }
59
60 EOF
61
62 $t->write_file('index.html', '');
63 $t->run();
64
65 ###############################################################################
66
67 like(http_get('/?1'), qr/x:0 y:0/, 'map default');
68 like(http_get('/?foo'), qr/x:bar y:0/, 'map foo bar');
69 like(http_get('/?example.com'), qr/x:0 y:foo/, 'map example.com foo');
70 like(http_get('/?example.org'), qr/x:0 y:wild/, 'map example.org wildcard');
71
72 TODO: {
73 local $TODO = 'not yet';
74
75 like(http_get('/?example.com.'), qr/x:0 y:foo/, 'map example.com. foo');
76
77 }
78
79 ###############################################################################