Mercurial > hg > nginx-tests
comparison stream_map.t @ 965:75ad4a978306
Tests: stream map module basic tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 05 Jul 2016 20:33:53 +0300 |
parents | |
children | 882267679006 |
comparison
equal
deleted
inserted
replaced
964:cca37c930b29 | 965:75ad4a978306 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for stream map 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 use Test::Nginx::Stream qw/ stream /; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 my $t = Test::Nginx->new()->has(qw/stream stream_return stream_map/) | |
27 ->has(qw/http rewrite/); | |
28 | |
29 $t->write_file_expand('nginx.conf', <<'EOF'); | |
30 | |
31 %%TEST_GLOBALS%% | |
32 | |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 stream { | |
39 map $server_port $x { | |
40 %%PORT_0%% literal; | |
41 default default; | |
42 ~(%%PORT_2%%) $1; | |
43 ~(?P<ncap>%%PORT_3%%) $ncap; | |
44 } | |
45 | |
46 server { | |
47 listen 127.0.0.1:%%PORT_0%%; | |
48 listen 127.0.0.1:%%PORT_1%%; | |
49 listen 127.0.0.1:%%PORT_2%%; | |
50 listen 127.0.0.1:%%PORT_3%%; | |
51 return $x; | |
52 } | |
53 | |
54 server { | |
55 listen 127.0.0.1:%%PORT_4%%; | |
56 return $x:${x}; | |
57 } | |
58 } | |
59 | |
60 EOF | |
61 | |
62 $t->try_run('no stream map')->plan(5); | |
63 | |
64 ############################################################################### | |
65 | |
66 is(stream('127.0.0.1:' . port(0))->read(), 'literal', 'literal'); | |
67 is(stream('127.0.0.1:' . port(1))->read(), 'default', 'default'); | |
68 is(stream('127.0.0.1:' . port(2))->read(), port(2), 'capture'); | |
69 is(stream('127.0.0.1:' . port(3))->read(), port(3), 'named capture'); | |
70 is(stream('127.0.0.1:' . port(4))->read(), 'default:default', 'braces'); | |
71 | |
72 ############################################################################### |