From c272b1bcd74c731dd63c414e480b20e46fc05cd7 Mon Sep 17 00:00:00 2001 From: Wangchong Zhou Date: Fri, 9 Aug 2024 18:11:44 +0800 Subject: [PATCH] chore(tests): port tools.http tests from EE --- spec/01-unit/05-utils_spec.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/01-unit/05-utils_spec.lua b/spec/01-unit/05-utils_spec.lua index e3100490ebec..f93d682f4f89 100644 --- a/spec/01-unit/05-utils_spec.lua +++ b/spec/01-unit/05-utils_spec.lua @@ -179,6 +179,29 @@ describe("Utils", function() assert.is_true(tools_http.check_https(true, false)) assert.is_true(tools_http.check_https(true, true)) end) + + it("test parsing directive header", function() + -- test null + assert.same(tools_http.parse_directive_header(nil), {}) + + -- test empty string + assert.same(tools_http.parse_directive_header(""), {}) + + -- test string + assert.same(tools_http.parse_directive_header("cache-key=kong-cache,cache-age=300"), { + ["cache-age"] = 300, + ["cache-key"] = "kong-cache", + }) + + -- test table + assert.same(tools_http.parse_directive_header({ + "cache-age=300", + "cache-key=kong-cache", + }), { + ["cache-age"] = 300, + ["cache-key"] = "kong-cache", + }) + end) end) end)