diff --git a/kong/clustering/services/sync/validate.lua b/kong/clustering/services/sync/validate.lua index e23e3a3c9b0..e3969785b21 100644 --- a/kong/clustering/services/sync/validate.lua +++ b/kong/clustering/services/sync/validate.lua @@ -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 = {} @@ -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 diff --git a/spec/02-integration/18-hybrid_rpc/10-validate_deltas_spec.lua b/spec/02-integration/18-hybrid_rpc/10-validate_deltas_spec.lua index 9b186a761fd..269c492dda8 100644 --- a/spec/02-integration/18-hybrid_rpc/10-validate_deltas_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/10-validate_deltas_spec.lua @@ -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 diff --git a/spec/fixtures/custom_plugins/kong/plugins/rpc-validation-test/handler.lua b/spec/fixtures/custom_plugins/kong/plugins/rpc-validation-test/handler.lua index b450a21ee88..9bd56f38f2f 100644 --- a/spec/fixtures/custom_plugins/kong/plugins/rpc-validation-test/handler.lua +++ b/spec/fixtures/custom_plugins/kong/plugins/rpc-validation-test/handler.lua @@ -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")