Welcome! Log In Create A New Profile

Advanced

Re: [PATCH] Proxy: support variables for proxy_method directive

Maxim Dounin
October 26, 2016 01:40PM
Hello!

On Fri, Oct 21, 2016 at 11:53:11PM +0300, Dmitry Lazurkin wrote:

> Add more tests.
>
> # HG changeset patch
> # User Dmitry Lazurkin <dilaz03@gmail.com>
> # Date 1476632999 -10800
> # Sun Oct 16 18:49:59 2016 +0300
> # Node ID 916ac83eed31a4e7f6f303e28867b925fc62bc27
> # Parent 1b11a12be17913a75e81d318dcb6b912eac5f29e
> Tests: add tests for proxy_method directive.
>
> diff -r 1b11a12be179 -r 916ac83eed31 proxy_method.t
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/proxy_method.t Sun Oct 16 18:49:59 2016 +0300
> @@ -0,0 +1,86 @@
> +#!/usr/bin/perl
> +
> +# (C) Dmitry Lazurkin
> +
> +# Tests for proxy_method.
> +
> +###############################################################################
> +
> +use warnings;
> +use strict;
> +
> +use Test::More;
> +
> +BEGIN { use FindBin; chdir($FindBin::Bin); }
> +
> +use lib 'lib';
> +use Test::Nginx;
> +
> +###############################################################################
> +
> +select STDERR; $| = 1;
> +select STDOUT; $| = 1;
> +
> +my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(4)
> + ->write_file_expand('nginx.conf', <<'EOF');
> +
> +%%TEST_GLOBALS%%
> +
> +daemon off;
> +
> +events {
> +}
> +
> +http {
> + %%TEST_GLOBALS_HTTP%%
> +
> + server {
> + listen 127.0.0.1:8080;
> + server_name localhost;
> +
> + location /preserve {
> + proxy_pass http://127.0.0.1:8080/get-method;
> + }
> +
> + location /const {
> + proxy_pass http://127.0.0.1:8080/get-method;
> + proxy_method POST;
> + }
> +
> + location /var {
> + proxy_pass http://127.0.0.1:8080/get-method;
> + proxy_method $arg_method;
> + }
> +
> + location /parent {
> + proxy_method POST;
> + location /parent/child {
> + proxy_pass http://127.0.0.1:8080/get-method;
> + }
> + }
> +
> + location /get-method {
> + return 200 "request_method=$request_method";
> + }
> + }
> +}
> +
> +EOF
> +
> +$t->run();
> +
> +###############################################################################
> +
> +like(http_get('/preserve'), qr/request_method=GET/,
> + 'proxy_method from request');
> +
> +like(http_get('/const'), qr/request_method=POST/,
> + 'proxy_method from constant');
> +
> +like(http_get('/var?method=POST'), qr/request_method=POST/,
> + 'proxy_method from variable');
> +
> +like(http_get('/parent/child'), qr/request_method=POST/,
> + 'proxy_method from parent');
> +
> +###############################################################################

Such a test will fail on versions without variables support in
proxy_method. This is a problem, as the same test suite is used
to test both mainline and stable. To address this we use
conditional TODO tests with version checked:

diff --git a/proxy_method.t b/proxy_method.t
--- a/proxy_method.t
+++ b/proxy_method.t
@@ -77,9 +77,14 @@ like(http_get('/preserve'), qr/request_m
like(http_get('/const'), qr/request_method=POST/,
'proxy_method from constant');

+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.11.6');
+
like(http_get('/var?method=POST'), qr/request_method=POST/,
'proxy_method from variable');

+}
+
like(http_get('/parent/child'), qr/request_method=POST/,
'proxy_method from parent');

Additionally, style is slighly different in our test scripts for
historical reasons, tabs are used to indent perl code.

Committed with the above changes, thanks.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Proxy: support variables for proxy_method directive

Dmitry Lazurkin 639 October 21, 2016 04:54PM

Re: [PATCH] Proxy: support variables for proxy_method directive

Maxim Dounin 298 October 26, 2016 01:40PM

Re: [PATCH] Proxy: support variables for proxy_method directive

Dmitry Lazurkin 300 October 28, 2016 09:18AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 204
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready