Skip to content

Commit

Permalink
t: test maintenance mode policy
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Moran committed Feb 28, 2018
1 parent 80cd176 commit 8546b16
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions examples/policies/t/apicast-policy-maintenance-mode.t
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 8546b16

Please sign in to comment.