From 9110f5cf4ad091cfa299b74c42ff2f9bc5065ab2 Mon Sep 17 00:00:00 2001 From: MonkeyDLufy Date: Mon, 29 Jan 2024 15:53:07 +0800 Subject: [PATCH 1/2] test case for support built-in variables in response_headers in mocking plugin --- t/plugin/mocking.t | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/t/plugin/mocking.t b/t/plugin/mocking.t index 46d82ef80a8f..6d837089adf0 100644 --- a/t/plugin/mocking.t +++ b/t/plugin/mocking.t @@ -465,3 +465,42 @@ GET /hello --- response_headers X-Apisix: is, cool X-Really: yes + + + +=== TEST 21: set route (return headers support built-in variables) +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "plugins": { + "mocking": { + "response_example": "hello world", + "response_headers": { + "X-route-id": "$route_id" + } + } + }, + "uri": "/hello" + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- response_body +passed + + + +=== TEST 22: hit route +--- request +GET /hello +--- response_headers +X-route-id: 1 From 2a78912ccb067ede89866192809bae12205258a8 Mon Sep 17 00:00:00 2001 From: MonkeyDLufy Date: Mon, 29 Jan 2024 15:59:42 +0800 Subject: [PATCH 2/2] Update mocking.t --- t/plugin/mocking.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/plugin/mocking.t b/t/plugin/mocking.t index 6d837089adf0..d5415918abb0 100644 --- a/t/plugin/mocking.t +++ b/t/plugin/mocking.t @@ -480,7 +480,7 @@ X-Really: yes "mocking": { "response_example": "hello world", "response_headers": { - "X-route-id": "$route_id" + "X-Route-Id": "$route_id" } } }, @@ -503,4 +503,4 @@ passed --- request GET /hello --- response_headers -X-route-id: 1 +X-Route-Id: 1