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
fffonion and ADD-SP authored Aug 12, 2024
1 parent c2e9f99 commit 97b1680
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

1 comment on commit 97b1680

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:97b16801b091551065e211a11eaa612696bfd3eb
Artifacts available https://github.com/Kong/kong/actions/runs/10357294142

Please sign in to comment.