Skip to content

Commit

Permalink
test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Nov 3, 2023
1 parent bb0c972 commit a1fad05
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion spec/01-unit/01-db/01-schema/06-routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ describe("routes schema (flavor = traditional_compatible)", function()
reload_flavor("traditional_compatible")
setup_global_env()

it("validates a valid route", function()
it("validates a valid http route", function()
local route = {
id = a_valid_uuid,
name = "my_route",
Expand All @@ -1351,6 +1351,21 @@ describe("routes schema (flavor = traditional_compatible)", function()
assert.falsy(route.strip_path)
end)

it("validates a valid stream route", function()
local route = {
id = a_valid_uuid,
name = "my_route",
protocols = { "tcp" },
sources = { { ip = "1.2.3.4", port = 80 } },
service = { id = another_uuid },
}
route = Routes:process_auto_fields(route, "insert")
assert.truthy(route.created_at)
assert.truthy(route.updated_at)
assert.same(route.created_at, route.updated_at)
assert.truthy(Routes:validate(route))
end)

it("fails when path is invalid", function()
local route = {
id = a_valid_uuid,
Expand All @@ -1370,6 +1385,23 @@ describe("routes schema (flavor = traditional_compatible)", function()
assert.falsy(errs["@entity"])
end)

it("fails when ip address is invalid", function()
local route = {
id = a_valid_uuid,
name = "my_route",
protocols = { "tcp" },
sources = { { ip = "x.x.x.x", port = 80 } },
service = { id = another_uuid },
}
route = Routes:process_auto_fields(route, "insert")
local ok, errs = Routes:validate_insert(route)
assert.falsy(ok)
assert.truthy(errs["sources"])

-- verified by `schema/typedefs.lua`
assert.falsy(errs["@entity"])
end)

it("won't fail when rust.regex update to 1.8", function()
local route = {
id = a_valid_uuid,
Expand Down

0 comments on commit a1fad05

Please sign in to comment.