annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
965
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for stream map module.
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx::Stream qw/ stream /;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 my $t = Test::Nginx->new()->has(qw/stream stream_return stream_map/)
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 ->has(qw/http rewrite/);
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 $t->write_file_expand('nginx.conf', <<'EOF');
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 %%TEST_GLOBALS%%
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 daemon off;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 events {
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 }
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 stream {
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 map $server_port $x {
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 %%PORT_0%% literal;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 default default;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 ~(%%PORT_2%%) $1;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 ~(?P<ncap>%%PORT_3%%) $ncap;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 }
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 server {
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 listen 127.0.0.1:%%PORT_0%%;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 listen 127.0.0.1:%%PORT_1%%;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 listen 127.0.0.1:%%PORT_2%%;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 listen 127.0.0.1:%%PORT_3%%;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 return $x;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 }
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 server {
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 listen 127.0.0.1:%%PORT_4%%;
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 return $x:${x};
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 }
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 }
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 EOF
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 $t->try_run('no stream map')->plan(5);
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 ###############################################################################
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 is(stream('127.0.0.1:' . port(0))->read(), 'literal', 'literal');
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 is(stream('127.0.0.1:' . port(1))->read(), 'default', 'default');
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 is(stream('127.0.0.1:' . port(2))->read(), port(2), 'capture');
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 is(stream('127.0.0.1:' . port(3))->read(), port(3), 'named capture');
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 is(stream('127.0.0.1:' . port(4))->read(), 'default:default', 'braces');
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71
75ad4a978306 Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 ###############################################################################