Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
wip-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
kikito committed Jun 8, 2020
1 parent f91b255 commit 9a7ae7d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
18 changes: 17 additions & 1 deletion kong/plugins/zipkin/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ local static_tag = Schema.define {
},
}

local validate_static_tags = function(tags)
if type(tags) ~= "table" then
return true
end
local found = {}
for i = 1, #tags do
local name = tags[i].name
if found[name] then
return nil, "repeating tags are not allowed: " .. name
end
found[name] = true
end
return true
end

return {
name = "zipkin",
fields = {
Expand All @@ -40,7 +55,8 @@ return {
{ traceid_byte_count = { type = "integer", required = true, default = 16, one_of = { 8, 16 } } },
{ header_type = { type = "string", required = true, default = "preserve",
one_of = { "preserve", "b3", "b3-single", "w3c" } } },
{ static_tags = { type = "array", elements = static_tag } }
{ static_tags = { type = "array", elements = static_tag,
custom_validator = validate_static_tags } }
},
}, },
},
Expand Down
20 changes: 20 additions & 0 deletions spec/schema_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local schema_def = require "kong.plugins.zipkin.schema"
local v = require("spec.helpers").validate_plugin_config_schema

describe("Plugin: Zipkin (schema)", function()
it("rejects repeated tags", function()
local ok, err = v({
http_endpoint = "http://example.dev",
static_tags = {
{ name = "foo", value = "bar" },
{ name = "foo", value = "baz" },
},
}, schema_def)

assert.is_falsy(ok)
assert.same({
static_tags = "repeated tags are not allowed: foo"
}, err)
end)
end)

0 comments on commit 9a7ae7d

Please sign in to comment.