Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(tools): add tests against kong.tools.http.parse_directive_header() #13482

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading