Mercurial > hg > nginx-tests
annotate stream_map.t @ 1993:6b1222de8286
Tests: fixed prerequisites for regular expressions in maps.
Regular expressions in maps are only recognized when nginx is compiled
with the PCRE library. The simplest way to make sure it is the case
is to require the rewrite module, which cannot be compiled in without
the PCRE library.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 01 Aug 2024 10:37:20 +0300 |
parents | f3ba4c74de31 |
children |
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 |
1993
6b1222de8286
Tests: fixed prerequisites for regular expressions in maps.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1609
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_return stream_map rewrite/) |
965
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 { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1251
diff
changeset
|
39 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1251
diff
changeset
|
40 |
965
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 map $server_port $x { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
42 %%PORT_8080%% literal; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
43 default default; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
44 ~(%%PORT_8082%%) $1; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
45 ~(?P<ncap>%%PORT_8083%%) $ncap; |
965
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 } |
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
49 listen 127.0.0.1:8080; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
50 listen 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
51 listen 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
52 listen 127.0.0.1:8083; |
965
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 return $x; |
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
57 listen 127.0.0.1:8084; |
965
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 return $x:${x}; |
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 } |
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 EOF |
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
64 $t->run()->plan(5); |
965
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 ############################################################################### |
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
68 is(stream('127.0.0.1:' . port(8080))->read(), 'literal', 'literal'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
69 is(stream('127.0.0.1:' . port(8081))->read(), 'default', 'default'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
70 is(stream('127.0.0.1:' . port(8082))->read(), port(8082), 'capture'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
71 is(stream('127.0.0.1:' . port(8083))->read(), port(8083), 'named capture'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
965
diff
changeset
|
72 is(stream('127.0.0.1:' . port(8084))->read(), 'default:default', 'braces'); |
965
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
75ad4a978306
Tests: stream map module basic tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 ############################################################################### |