Skip to content

Commit

Permalink
tests(clustering/rpc): more cases for deltas validation (#14243)
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored Feb 7, 2025
1 parent 0ba6c08 commit 7d0e5c9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kong/clustering/services/sync/validate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local pretty_print_error = declarative.pretty_print_error
local function validate_deltas(deltas, is_full_sync)

local errs = {}
local errs_n = 0

-- generate deltas table mapping primary key string to entity item
local deltas_map = {}
Expand Down Expand Up @@ -45,7 +46,8 @@ local function validate_deltas(deltas, is_full_sync)

local ok, err_t = dao.schema:validate(copy)
if not ok then
errs[#errs + 1] = { [delta_type] = err_t }
errs_n = errs_n + 1
errs[errs_n] = { [delta_type] = err_t }
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/02-integration/18-hybrid_rpc/10-validate_deltas_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,18 @@ for _, strategy in helpers.each_strategy() do
"[error]", true, 10)
assert.logfile(name).has.line(
"unable to create worker mutex and sync", true, 10)

assert.logfile(name).has.line(
"'name': required field missing", true, 10)
assert.logfile(name).has.line(
"'meta': expected a record", true, 10)
assert.logfile(name).has.line(
"'config': expected a record", true, 10)

assert.logfile(name).has.line(
"'key': expected a string", true, 10)
assert.logfile(name).has.line(
"'value': expected a string", true, 10)

local name = nil

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@ function RpcSyncV2ValidationHandler:init_worker()
{
entity = {
id = fake_uuid,
meta = "wrong", -- should be a record,
config = 100, -- should be a record,
},
type = "workspaces",
version = latest_version,
ws_id = fake_uuid,
},
{
entity = {
key = 100, -- should be a string
value = {}, -- should be a string
},
type = "parameters",
version = latest_version,
ws_id = fake_uuid,
},
}

ngx.log(ngx.DEBUG, "kong.sync.v2.get_delta ok")
Expand Down

1 comment on commit 7d0e5c9

@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-dev:7d0e5c9e908cf4b97cabf662a6f825d955980e8b
Artifacts available https://github.com/Kong/kong/actions/runs/13192487242

Please sign in to comment.