Skip to content

Commit

Permalink
test: add test for KeyMatch5
Browse files Browse the repository at this point in the history
  • Loading branch information
mikyll committed Nov 20, 2024
1 parent 7ae73b0 commit 8b9801d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/util/built_in_functions_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,46 @@ describe("BuiltInFunctions tests", function ()
assert.is.False(BuiltInFunctions.IPMatch("192.168.2.124", "192.168.2.123"))
assert.is.False(BuiltInFunctions.IPMatch("192.166.2.123", "192.168.2.123"))
end)

it("keyMatch5 tests", function ()
assert.has_error(function () BuiltInFunctions.keyMatch5Func({"/foo"}) end, "Expected 2 arguments, but got 1")
assert.has_error(function () BuiltInFunctions.keyMatch5Func({"/foo/create/123", "/foo/*", "/foo/update/123"}) end, "Expected 2 arguments, but got 3")
assert.has_error(function () BuiltInFunctions.keyMatch5Func({"/parent/123", true}) end, "Argument must be a string")

assert.is.True(BuiltInFunctions.keyMatch5("/parent/child?status=1&type=2", "/parent/child"))
assert.is.False(BuiltInFunctions.keyMatch5("/parent?status=1&type=2", "/parent/child"))

assert.is.True(BuiltInFunctions.keyMatch5("/parent/child/?status=1&type=2", "/parent/child/"))
assert.is.False(BuiltInFunctions.keyMatch5("/parent/child/?status=1&type=2", "/parent/child"))
assert.is.False(BuiltInFunctions.keyMatch5("/parent/child?status=1&type=2", "/parent/child/"))

assert.is.True(BuiltInFunctions.keyMatch5("/foo", "/foo"))
assert.is.True(BuiltInFunctions.keyMatch5("/foo", "/foo*"))
assert.is.False(BuiltInFunctions.keyMatch5("/foo", "/foo/*"))
assert.is.False(BuiltInFunctions.keyMatch5("/foo/bar", "/foo"))
assert.is.False(BuiltInFunctions.keyMatch5("/foo/bar", "/foo*"))
assert.is.True(BuiltInFunctions.keyMatch5("/foo/bar", "/foo/*"))
assert.is.False(BuiltInFunctions.keyMatch5("/foobar", "/foo"))
assert.is.False(BuiltInFunctions.keyMatch5("/foobar", "/foo*"))
assert.is.False(BuiltInFunctions.keyMatch5("/foobar", "/foo/*"))

assert.is.False(BuiltInFunctions.keyMatch5("/", "/{resource}"))
assert.is.True(BuiltInFunctions.keyMatch5("/resource1", "/{resource}"))
assert.is.False(BuiltInFunctions.keyMatch5("/myid", "/{id}/using/{resId}"))
assert.is.True(BuiltInFunctions.keyMatch5("/myid/using/myresid", "/{id}/using/{resId}"))

assert.is.False(BuiltInFunctions.keyMatch5("/proxy/myid", "/proxy/{id}/*"))
assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/", "/proxy/{id}/*"))
assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/res", "/proxy/{id}/*"))
assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/res/res2", "/proxy/{id}/*"))
assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/res/res2/res3", "/proxy/{id}/*"))
assert.is.False(BuiltInFunctions.keyMatch5("/proxy/", "/proxy/{id}/*"))

assert.is.False(BuiltInFunctions.keyMatch5("/proxy/myid?status=1&type=2", "/proxy/{id}/*"))
assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/", "/proxy/{id}/*"))
assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/res?status=1&type=2", "/proxy/{id}/*"))
assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/res/res2?status=1&type=2", "/proxy/{id}/*"))
assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/res/res2/res3?status=1&type=2", "/proxy/{id}/*"))
assert.is.False(BuiltInFunctions.keyMatch5("/proxy/", "/proxy/{id}/*"))
end)
end)

0 comments on commit 8b9801d

Please sign in to comment.