From 6c515ecc8be357e417e7f21e0ace77838dd2965d 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 | 91 +++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 t/apicast-policy-maintenance-mode.t diff --git a/t/apicast-policy-maintenance-mode.t b/t/apicast-policy-maintenance-mode.t new file mode 100644 index 000000000..5455a3b26 --- /dev/null +++ b/t/apicast-policy-maintenance-mode.t @@ -0,0 +1,91 @@ +use lib 't'; +use Test::APIcast::Blackbox 'no_plan'; + +repeat_each(1); +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) TODO - validate 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": "apicast.policy.maintenance_mode" }, + { "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 / { + echo 'No response from me!'; + } +--- request +GET / +--- 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) TODO - validate 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": "apicast.policy.maintenance_mode", + "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 / { + echo 'No response from me!'; + } +--- request +GET / +--- response_body +Be back soon +--- error_code: 501 +--- no_error_log +[error] \ No newline at end of file