From 4579a82c790ce162fc151a322825790fda983b99 Mon Sep 17 00:00:00 2001 From: Alan Moran Date: Tue, 23 Jan 2018 16:31:57 +1100 Subject: [PATCH] t: test maintenance mode policy --- .../t/apicast-policy-maintenance-mode.t | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 examples/policies/t/apicast-policy-maintenance-mode.t diff --git a/examples/policies/t/apicast-policy-maintenance-mode.t b/examples/policies/t/apicast-policy-maintenance-mode.t new file mode 100644 index 000000000..8471e1b13 --- /dev/null +++ b/examples/policies/t/apicast-policy-maintenance-mode.t @@ -0,0 +1,107 @@ +use lib 't'; +use Test::APIcast::Blackbox 'no_plan'; + +repeat_each(1); + +env_to_apicast( + 'APICAST_POLICY_LOAD_PATH' => "$ENV{PWD}/examples/policies" +); + +run_tests(); + +__DATA__ + +=== TEST 1: Use maintenance mode using default values +Testing 3 things: +1) Check default status code +2) Check default response message +3) Validates upstream doesn't get the request + +--- configuration +{ + "services": [ + { + "id": 42, + "backend_version": 1, + "backend_authentication_type": "service_token", + "backend_authentication_value": "token-value", + "proxy": { + "policy_chain": [ + { "name": "maintenance-mode", "version": "1.0.0" }, + { "name": "apicast.policy.apicast" } + ], + "api_backend": "http://test:$TEST_NGINX_SERVER_PORT/", + "proxy_rules": [ + { "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 2 } + ] + } + } + ] +} +--- upstream + location / { + content_by_lua_block { + local assert = require('luassert') + assert.is_nil(ngx.req.get_uri_args()) + ngx.say('No response from me'); + } + } +--- request +GET /?test +--- response_body +503 Service Unavailable - Maintenance +--- error_code: 503 +--- no_error_log +[error] + + +=== TEST 2: Use maintenance mode using custom values +Testing 3 things: +1) Check custom status code +2) Check custom response message +3) Validates upstream doesn't get request + +--- configuration +{ + "services": [{ + "id": 42, + "backend_version": 1, + "backend_authentication_type": "service_token", + "backend_authentication_value": "token-value", + "proxy": { + "policy_chain": [{ + "name": "maintenance-mode", "version": "1.0.0", + "configuration": { + "message": "Be back soon", + "status": 501 + } + }, + { + "name": "apicast.policy.apicast" + } + ], + "api_backend": "http://test:$TEST_NGINX_SERVER_PORT/", + "proxy_rules": [{ + "pattern": "/", + "http_method": "GET", + "metric_system_name": "hits", + "delta": 2 + }] + } + }] +} +--- upstream + location / { + content_by_lua_block { + local assert = require('luassert') + assert.is_nil(ngx.req.get_uri_args()) + ngx.say('No response from me'); + } + } +--- request +GET /?test +--- response_body +Be back soon +--- error_code: 501 +--- no_error_log +[error]