Skip to content

Commit

Permalink
tests(tools): add tests against `kong.tools.http.parse_directive_head…
Browse files Browse the repository at this point in the history
…er()` (#13482)

Co-authored-by: Qi <[email protected]>
(cherry picked from commit 97b1680)
  • Loading branch information
fffonion authored and windmgc committed Aug 19, 2024
1 parent dc3ba83 commit d818b55
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions spec/01-unit/05-utils_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,34 @@ 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()
-- EMPTY table return by the function with `nil` should be read-only
assert.is_false(pcall(function()
tools_http.parse_directive_header(nil)["foo"] = "bar"
end))

-- 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)

Expand Down

0 comments on commit d818b55

Please sign in to comment.