# HG changeset patch # User Andrei Belov # Date 1605192409 -10800 # Node ID f3ba4c74de3120dd5b0233aa4073112ecdaf088d # Parent 2f00ed2e0d1a62e706331da02149e5f552c694b7 Tests: added TEST_GLOBALS_STREAM variable support. diff --git a/README b/README --- a/README +++ b/README @@ -48,4 +48,8 @@ TEST_NGINX_GLOBALS_HTTP Sets additional directives in http context. +TEST_NGINX_GLOBALS_STREAM + + Sets additional directives in stream context. + Happy testing! diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm --- a/lib/Test/Nginx.pm +++ b/lib/Test/Nginx.pm @@ -548,6 +548,7 @@ sub write_file_expand($$) { $content =~ s/%%TEST_GLOBALS%%/$self->test_globals()/gmse; $content =~ s/%%TEST_GLOBALS_HTTP%%/$self->test_globals_http()/gmse; + $content =~ s/%%TEST_GLOBALS_STREAM%%/$self->test_globals_stream()/gmse; $content =~ s/%%TESTDIR%%/$self->{_testdir}/gms; $content =~ s/127\.0\.0\.1:(8\d\d\d)/'127.0.0.1:' . port($1)/gmse; @@ -689,6 +690,20 @@ sub test_globals_http() { $self->{_test_globals_http} = $s; } +sub test_globals_stream() { + my ($self) = @_; + + return $self->{_test_globals_stream} + if defined $self->{_test_globals_stream}; + + my $s = ''; + + $s .= $ENV{TEST_NGINX_GLOBALS_STREAM} + if $ENV{TEST_NGINX_GLOBALS_STREAM}; + + $self->{_test_globals_stream} = $s; +} + ############################################################################### sub log_core { diff --git a/proxy_protocol_ipv6.t b/proxy_protocol_ipv6.t --- a/proxy_protocol_ipv6.t +++ b/proxy_protocol_ipv6.t @@ -53,6 +53,8 @@ http { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen 127.0.0.1:8080; proxy_pass [::1]:%%PORT_8080%%; diff --git a/stream_access.t b/stream_access.t --- a/stream_access.t +++ b/stream_access.t @@ -35,6 +35,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen 127.0.0.1:8082; proxy_pass [::1]:%%PORT_8080%%; diff --git a/stream_access_log.t b/stream_access_log.t --- a/stream_access_log.t +++ b/stream_access_log.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + log_format test $server_addr; log_format vars $connection:$nginx_version:$hostname:$pid; log_format addr $binary_remote_addr:$remote_addr:$remote_port: diff --git a/stream_access_log_escape.t b/stream_access_log_escape.t --- a/stream_access_log_escape.t +++ b/stream_access_log_escape.t @@ -33,6 +33,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + map $pid $a { default '" \ "'; } diff --git a/stream_access_log_none.t b/stream_access_log_none.t --- a/stream_access_log_none.t +++ b/stream_access_log_none.t @@ -33,6 +33,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + map $pid $a { default '" \ "'; } diff --git a/stream_error_log.t b/stream_error_log.t --- a/stream_error_log.t +++ b/stream_error_log.t @@ -44,6 +44,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + upstream u { server 127.0.0.1:%%PORT_8983_UDP%% down; } diff --git a/stream_geo.t b/stream_geo.t --- a/stream_geo.t +++ b/stream_geo.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + geo $geo { 127.0.0.0/8 loopback; 192.0.2.0/24 test; diff --git a/stream_geo_binary.t b/stream_geo_binary.t --- a/stream_geo_binary.t +++ b/stream_geo_binary.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + geo $geo_base_create { ranges; include base.conf; diff --git a/stream_geo_ipv6.t b/stream_geo_ipv6.t --- a/stream_geo_ipv6.t +++ b/stream_geo_ipv6.t @@ -34,6 +34,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + geo $geo { ::1/128 loopback; 2001:0db8::/32 test; diff --git a/stream_geo_unix.t b/stream_geo_unix.t --- a/stream_geo_unix.t +++ b/stream_geo_unix.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + geo $geo { default default; 255.255.255.255 none; diff --git a/stream_geoip.t b/stream_geoip.t --- a/stream_geoip.t +++ b/stream_geoip.t @@ -38,6 +38,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + set_real_ip_from 127.0.0.1/32; geoip_country %%TESTDIR%%/country.dat; diff --git a/stream_js.t b/stream_js.t --- a/stream_js.t +++ b/stream_js.t @@ -59,6 +59,8 @@ http { } stream { + %%TEST_GLOBALS_STREAM%% + js_set $js_addr js_addr; js_set $js_var js_var; js_set $js_log js_log; diff --git a/stream_js_import.t b/stream_js_import.t --- a/stream_js_import.t +++ b/stream_js_import.t @@ -34,6 +34,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + js_set $test foo.bar.p; js_import lib.js; diff --git a/stream_js_object.t b/stream_js_object.t --- a/stream_js_object.t +++ b/stream_js_object.t @@ -49,6 +49,8 @@ http { } stream { + %%TEST_GLOBALS_STREAM%% + js_set $test test; js_include test.js; diff --git a/stream_js_variables.t b/stream_js_variables.t --- a/stream_js_variables.t +++ b/stream_js_variables.t @@ -49,6 +49,8 @@ http { } stream { + %%TEST_GLOBALS_STREAM%% + js_set $test_var test_var; js_set $test_not_found test_not_found; diff --git a/stream_limit_conn.t b/stream_limit_conn.t --- a/stream_limit_conn.t +++ b/stream_limit_conn.t @@ -33,6 +33,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + limit_conn_zone $binary_remote_addr zone=zone:1m; limit_conn_zone $binary_remote_addr zone=zone2:1m; diff --git a/stream_limit_conn_complex.t b/stream_limit_conn_complex.t --- a/stream_limit_conn_complex.t +++ b/stream_limit_conn_complex.t @@ -33,6 +33,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + limit_conn_zone $binary_remote_addr$server_port zone=zone:1m; server { diff --git a/stream_limit_conn_dry_run.t b/stream_limit_conn_dry_run.t --- a/stream_limit_conn_dry_run.t +++ b/stream_limit_conn_dry_run.t @@ -35,6 +35,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + limit_conn_zone $binary_remote_addr zone=zone:1m; log_format test $server_port:$limit_conn_status; diff --git a/stream_limit_rate.t b/stream_limit_rate.t --- a/stream_limit_rate.t +++ b/stream_limit_rate.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + # download and upload rates are set equal to the maximum # number of bytes transmitted diff --git a/stream_limit_rate2.t b/stream_limit_rate2.t --- a/stream_limit_rate2.t +++ b/stream_limit_rate2.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + # download and upload rates are set equal to the maximum # number of bytes transmitted diff --git a/stream_map.t b/stream_map.t --- a/stream_map.t +++ b/stream_map.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + map $server_port $x { %%PORT_8080%% literal; default default; diff --git a/stream_proxy.t b/stream_proxy.t --- a/stream_proxy.t +++ b/stream_proxy.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen 127.0.0.1:8080; proxy_pass 127.0.0.1:8081; diff --git a/stream_proxy_bind.t b/stream_proxy_bind.t --- a/stream_proxy_bind.t +++ b/stream_proxy_bind.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen 127.0.0.1:8081; proxy_bind 127.0.0.2; diff --git a/stream_proxy_complex.t b/stream_proxy_complex.t --- a/stream_proxy_complex.t +++ b/stream_proxy_complex.t @@ -34,6 +34,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + upstream %%PORT_8081%% { server 127.0.0.1:8091; } diff --git a/stream_proxy_next_upstream.t b/stream_proxy_next_upstream.t --- a/stream_proxy_next_upstream.t +++ b/stream_proxy_next_upstream.t @@ -35,6 +35,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + upstream u { server 127.0.0.1:8083 max_fails=0; server 127.0.0.1:8084 max_fails=0; diff --git a/stream_proxy_protocol.t b/stream_proxy_protocol.t --- a/stream_proxy_protocol.t +++ b/stream_proxy_protocol.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_protocol on; server { diff --git a/stream_proxy_protocol_ipv6.t b/stream_proxy_protocol_ipv6.t --- a/stream_proxy_protocol_ipv6.t +++ b/stream_proxy_protocol_ipv6.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen 127.0.0.1:8080; proxy_pass [::1]:%%PORT_8080%%; diff --git a/stream_proxy_protocol_ssl.t b/stream_proxy_protocol_ssl.t --- a/stream_proxy_protocol_ssl.t +++ b/stream_proxy_protocol_ssl.t @@ -40,6 +40,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_ssl on; proxy_protocol on; diff --git a/stream_proxy_ssl.t b/stream_proxy_ssl.t --- a/stream_proxy_ssl.t +++ b/stream_proxy_ssl.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_ssl on; proxy_ssl_session_reuse on; proxy_connect_timeout 2s; diff --git a/stream_proxy_ssl_certificate.t b/stream_proxy_ssl_certificate.t --- a/stream_proxy_ssl_certificate.t +++ b/stream_proxy_ssl_certificate.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_ssl on; proxy_ssl_session_reuse off; diff --git a/stream_proxy_ssl_conf_command.t b/stream_proxy_ssl_conf_command.t --- a/stream_proxy_ssl_conf_command.t +++ b/stream_proxy_ssl_conf_command.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen 127.0.0.1:8080; proxy_pass 127.0.0.1:8081; diff --git a/stream_proxy_ssl_name.t b/stream_proxy_ssl_name.t --- a/stream_proxy_ssl_name.t +++ b/stream_proxy_ssl_name.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_ssl on; proxy_ssl_session_reuse off; diff --git a/stream_proxy_ssl_name_complex.t b/stream_proxy_ssl_name_complex.t --- a/stream_proxy_ssl_name_complex.t +++ b/stream_proxy_ssl_name_complex.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_ssl on; proxy_ssl_session_reuse off; diff --git a/stream_proxy_ssl_verify.t b/stream_proxy_ssl_verify.t --- a/stream_proxy_ssl_verify.t +++ b/stream_proxy_ssl_verify.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_ssl on; proxy_ssl_verify on; diff --git a/stream_realip.t b/stream_realip.t --- a/stream_realip.t +++ b/stream_realip.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen 127.0.0.1:8083 proxy_protocol; listen 127.0.0.1:8084; diff --git a/stream_realip_hostname.t b/stream_realip_hostname.t --- a/stream_realip_hostname.t +++ b/stream_realip_hostname.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen unix:%%TESTDIR%%/unix.sock proxy_protocol; listen 127.0.0.1:8080; diff --git a/stream_resolver.t b/stream_resolver.t --- a/stream_resolver.t +++ b/stream_resolver.t @@ -34,6 +34,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + map $server_port $upstream { %%PORT_8081%% a.example.com:%%PORT_8090%%; %%PORT_8082%% a.example.com; diff --git a/stream_set.t b/stream_set.t --- a/stream_set.t +++ b/stream_set.t @@ -35,6 +35,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + map 0 $map_var { default "original"; diff --git a/stream_split_clients.t b/stream_split_clients.t --- a/stream_split_clients.t +++ b/stream_split_clients.t @@ -35,6 +35,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + split_clients $connection $variant { 51.2% "first"; 10% "second"; diff --git a/stream_ssl.t b/stream_ssl.t --- a/stream_ssl.t +++ b/stream_ssl.t @@ -47,6 +47,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + ssl_certificate_key localhost.key; ssl_certificate localhost.crt; ssl_session_tickets off; diff --git a/stream_ssl_certificate.t b/stream_ssl_certificate.t --- a/stream_ssl_certificate.t +++ b/stream_ssl_certificate.t @@ -55,6 +55,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + geo $one { default one; } diff --git a/stream_ssl_conf_command.t b/stream_ssl_conf_command.t --- a/stream_ssl_conf_command.t +++ b/stream_ssl_conf_command.t @@ -43,6 +43,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen 127.0.0.1:8443 ssl; return OK; diff --git a/stream_ssl_preread.t b/stream_ssl_preread.t --- a/stream_ssl_preread.t +++ b/stream_ssl_preread.t @@ -35,6 +35,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + log_format status $status; map $ssl_preread_server_name $name { diff --git a/stream_ssl_preread_alpn.t b/stream_ssl_preread_alpn.t --- a/stream_ssl_preread_alpn.t +++ b/stream_ssl_preread_alpn.t @@ -35,6 +35,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + map $ssl_preread_alpn_protocols $name { "" 127.0.0.1:8093; default $ssl_preread_alpn_protocols; diff --git a/stream_ssl_preread_protocol.t b/stream_ssl_preread_protocol.t --- a/stream_ssl_preread_protocol.t +++ b/stream_ssl_preread_protocol.t @@ -33,6 +33,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen 127.0.0.1:8080; ssl_preread on; diff --git a/stream_ssl_realip.t b/stream_ssl_realip.t --- a/stream_ssl_realip.t +++ b/stream_ssl_realip.t @@ -41,6 +41,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + ssl_certificate_key localhost.key; ssl_certificate localhost.crt; diff --git a/stream_ssl_variables.t b/stream_ssl_variables.t --- a/stream_ssl_variables.t +++ b/stream_ssl_variables.t @@ -53,6 +53,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + ssl_certificate_key localhost.key; ssl_certificate localhost.crt; ssl_session_cache builtin; diff --git a/stream_ssl_verify_client.t b/stream_ssl_verify_client.t --- a/stream_ssl_verify_client.t +++ b/stream_ssl_verify_client.t @@ -47,6 +47,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + log_format status $status; ssl_certificate_key 1.example.com.key; diff --git a/stream_status_variable.t b/stream_status_variable.t --- a/stream_status_variable.t +++ b/stream_status_variable.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + log_format status $status; limit_conn_zone $binary_remote_addr zone=zone:1m; diff --git a/stream_tcp_nodelay.t b/stream_tcp_nodelay.t --- a/stream_tcp_nodelay.t +++ b/stream_tcp_nodelay.t @@ -38,6 +38,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_buffer_size 1; tcp_nodelay off; diff --git a/stream_udp_limit_conn.t b/stream_udp_limit_conn.t --- a/stream_udp_limit_conn.t +++ b/stream_udp_limit_conn.t @@ -34,6 +34,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + limit_conn_zone $binary_remote_addr zone=zone:1m; limit_conn_zone $binary_remote_addr zone=zone2:1m; diff --git a/stream_udp_limit_rate.t b/stream_udp_limit_rate.t --- a/stream_udp_limit_rate.t +++ b/stream_udp_limit_rate.t @@ -34,6 +34,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_requests 2; proxy_responses 1; proxy_timeout 3s; diff --git a/stream_udp_proxy.t b/stream_udp_proxy.t --- a/stream_udp_proxy.t +++ b/stream_udp_proxy.t @@ -33,6 +33,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_timeout 1s; server { diff --git a/stream_udp_proxy_requests.t b/stream_udp_proxy_requests.t --- a/stream_udp_proxy_requests.t +++ b/stream_udp_proxy_requests.t @@ -34,6 +34,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_timeout 2100ms; log_format status $status; diff --git a/stream_udp_stream.t b/stream_udp_stream.t --- a/stream_udp_stream.t +++ b/stream_udp_stream.t @@ -33,6 +33,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_timeout 1s; server { diff --git a/stream_udp_upstream.t b/stream_udp_upstream.t --- a/stream_udp_upstream.t +++ b/stream_udp_upstream.t @@ -34,6 +34,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_responses 1; proxy_timeout 1s; diff --git a/stream_udp_upstream_hash.t b/stream_udp_upstream_hash.t --- a/stream_udp_upstream_hash.t +++ b/stream_udp_upstream_hash.t @@ -35,6 +35,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_responses 1; proxy_timeout 1s; diff --git a/stream_udp_upstream_least_conn.t b/stream_udp_upstream_least_conn.t --- a/stream_udp_upstream_least_conn.t +++ b/stream_udp_upstream_least_conn.t @@ -34,6 +34,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_responses 1; proxy_timeout 1s; diff --git a/stream_udp_wildcard.t b/stream_udp_wildcard.t --- a/stream_udp_wildcard.t +++ b/stream_udp_wildcard.t @@ -40,6 +40,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen %%PORT_8999_UDP%% udp; return $server_addr; diff --git a/stream_unix.t b/stream_unix.t --- a/stream_unix.t +++ b/stream_unix.t @@ -38,6 +38,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + upstream u { server unix:%%TESTDIR%%/unix.sock; } diff --git a/stream_upstream.t b/stream_upstream.t --- a/stream_upstream.t +++ b/stream_upstream.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + log_format bytes $upstream_addr! $upstream_bytes_sent!$upstream_bytes_received; diff --git a/stream_upstream_hash.t b/stream_upstream_hash.t --- a/stream_upstream_hash.t +++ b/stream_upstream_hash.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + upstream hash { hash $remote_addr; server 127.0.0.1:8082; diff --git a/stream_upstream_least_conn.t b/stream_upstream_least_conn.t --- a/stream_upstream_least_conn.t +++ b/stream_upstream_least_conn.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + upstream u { least_conn; server 127.0.0.1:8081; diff --git a/stream_upstream_max_conns.t b/stream_upstream_max_conns.t --- a/stream_upstream_max_conns.t +++ b/stream_upstream_max_conns.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + upstream u_unlim { server 127.0.0.1:8081 max_conns=0; server 127.0.0.1:8082; diff --git a/stream_upstream_random.t b/stream_upstream_random.t --- a/stream_upstream_random.t +++ b/stream_upstream_random.t @@ -35,6 +35,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + upstream u { zone z 1m; random; diff --git a/stream_upstream_zone.t b/stream_upstream_zone.t --- a/stream_upstream_zone.t +++ b/stream_upstream_zone.t @@ -34,6 +34,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + log_format test $upstream_addr; upstream u { diff --git a/stream_upstream_zone_ssl.t b/stream_upstream_zone_ssl.t --- a/stream_upstream_zone_ssl.t +++ b/stream_upstream_zone_ssl.t @@ -36,6 +36,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + proxy_ssl on; proxy_ssl_session_reuse on; diff --git a/stream_variables.t b/stream_variables.t --- a/stream_variables.t +++ b/stream_variables.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen 127.0.0.1:8080; return $connection:$nginx_version:$hostname:$pid:$bytes_sent; diff --git a/worker_shutdown_timeout_stream.t b/worker_shutdown_timeout_stream.t --- a/worker_shutdown_timeout_stream.t +++ b/worker_shutdown_timeout_stream.t @@ -37,6 +37,8 @@ events { } stream { + %%TEST_GLOBALS_STREAM%% + server { listen 127.0.0.1:8025; proxy_pass 127.0.0.1:8026;