From d2eb86dc80fde8c45a0c68d7c1aa21da37b9b326 Mon Sep 17 00:00:00 2001 From: Hector Vido Date: Mon, 30 Oct 2023 23:55:41 -0300 Subject: [PATCH] Converted balancer and backend to APIcast::Blackbox --- t/backend.t | 38 +++++++++++++++++++++++++++++++------- t/balancer.t | 43 ++++++++++++++++++++++++++++++++----------- 2 files changed, 63 insertions(+), 18 deletions(-) diff --git a/t/backend.t b/t/backend.t index 532cf687c..d6775f41b 100644 --- a/t/backend.t +++ b/t/backend.t @@ -1,17 +1,41 @@ use lib 't'; -use Test::APIcast 'no_plan'; +use Test::APIcast::Blackbox 'no_plan'; + +repeat_each(1); run_tests(); __DATA__ -=== TEST 1: backend -This is just a simple demonstration of the +=== TEST 1: This is just a simple demonstration of the echo directive provided by ngx_http_echo_module. ---- config -include $TEST_NGINX_BACKEND_CONFIG; +--- configuration +{ + "services" : [ + { + "id": 42, + "backend_version": 1, + "proxy" : { + "api_backend": "http://test:$TEST_NGINX_SERVER_PORT/", + "proxy_rules": [ + { "pattern" : "/", "http_method" : "GET", "metric_system_name" : "bar", "delta" : 1} + ] + } + } + ] +} +--- backend +location /transactions/authrep.xml { + content_by_lua_block { + ngx.exit(200) + } +} +--- upstream +location / { + echo 'yay, api backend'; +} --- request -GET /transactions/authrep.xml +GET /?user_key=value --- response_body -transactions authrep! +yay, api backend --- error_code: 200 diff --git a/t/balancer.t b/t/balancer.t index 803632ef7..e12467a08 100644 --- a/t/balancer.t +++ b/t/balancer.t @@ -1,5 +1,5 @@ use lib 't'; -use Test::APIcast 'no_plan'; +use Test::APIcast::Blackbox 'no_plan'; $ENV{TEST_NGINX_HTTP_CONFIG} = "$Test::APIcast::path/http.d/*.conf"; $ENV{RESOLVER} = '127.0.1.1:5353'; @@ -19,19 +19,40 @@ Balancing different hosts does not leak memory. init_by_lua_block { require('resty.balancer.round_robin').cache_size = 1 } ---- config - location = /t { - content_by_lua_block { - local round_robin = require('resty.balancer.round_robin') - local balancer = round_robin.new() +--- configuration +{ + "services" : [ + { + "id": 42, + "backend_version": 1, + "proxy" : { + "api_backend": "http://test:$TEST_NGINX_SERVER_PORT/", + "proxy_rules": [ + { "pattern" : "/", "http_method" : "GET", "metric_system_name" : "bar", "delta" : 1 } + ] + } + } + ] +} +--- backend +location /transactions/authrep.xml { + content_by_lua_block { + ngx.exit(200) + } +} +--- upstream +location = / { + content_by_lua_block { + local round_robin = require('resty.balancer.round_robin') + local balancer = round_robin.new() - local peers = { hash = ngx.var.request_id, cur = 1, 1, 2 } - local peer = round_robin.call(peers) + local peers = { hash = ngx.var.request_id, cur = 1, 1, 2 } + local peer = round_robin.call(peers) - ngx.print(peer) - } + ngx.print(peer) } +} --- pipelined_requests eval -[ "GET /t", "GET /t" ] +[ "GET /?user_key=value", "GET /?user_key=value" ] --- response_body eval [ "1", "1" ]