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]>
  • Loading branch information
2 people authored and ProBrian committed Aug 13, 2024
1 parent 30a5205 commit 51fab9e
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 @@ -179,6 +179,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 51fab9e

Please sign in to comment.