Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(compatibility): add a test case for config compatibility between dp and cp #10759

Merged
merged 4 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions spec/01-unit/19-hybrid/03-compat_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,64 @@ describe("kong.clustering.compat", function()
end)
end)


for _, strategy in helpers.each_strategy() do
-- bypass test case against cassandra backend
local compat_describe = (strategy ~= "cassandra") and describe or pending

compat_describe("[#" .. strategy .. "]: check compat for entities those have `updated_at` field", function()
windmgc marked this conversation as resolved.
Show resolved Hide resolved
local bp, db, entity_names

setup(function()
-- excludes entities not exportable: clustering_data_planes,
entity_names = {
"services",
"routes",
"ca_certificates",
"certificates",
"consumers",
"targets",
"upstreams",
"plugins",
"workspaces",
"snis",
}

local plugins_enabled = { "key-auth" }
bp, db = helpers.get_db_utils(strategy, entity_names, plugins_enabled)

for _, name in ipairs(entity_names) do
if name == "plugins" then
local plugin = {
name = "key-auth",
config = {
-- key_names has default value so we don't have to provide it
-- key_names = {}
}
}
bp[name]:insert(plugin)
elseif name == "routes" then
bp[name]:insert({ hosts = { "test1.test" }, })
else
bp[name]:insert()
end
end
end)

teardown(function()
for _, entity_name in ipairs(entity_names) do
db[entity_name]:truncate()
end
end)

it(function()
local config = { config_table = declarative.export_config() }
local has_update = compat.update_compatible_payload(config, "3.0.0", "test_")
assert.truthy(has_update)
end)
end)
end

describe("core entities compatible changes", function()
local config, db

Expand Down
52 changes: 33 additions & 19 deletions spec/fixtures/blueprints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,19 @@ Sequence.__index = Sequence


function Sequence:next()
self.count = self.count + 1
return fmt(self.sequence_string, self.count)
return fmt(self.sequence_string, self:gen())
end

function Sequence:gen()
self.count = self.count + 1
return self.count
end

local function new_sequence(sequence_string)
local function new_sequence(sequence_string, gen)
return setmetatable({
count = 0,
sequence_string = sequence_string,
gen = gen,
}, Sequence)
end

Expand All @@ -95,7 +99,30 @@ local _M = {}
function _M.new(db)
local res = {}

-- prepare Sequences and random values
local sni_seq = new_sequence("server-name-%d")
local upstream_name_seq = new_sequence("upstream-%d")
local consumer_custom_id_seq = new_sequence("consumer-id-%d")
local consumer_username_seq = new_sequence("consumer-username-%d")
local named_service_name_seq = new_sequence("service-name-%d")
local named_service_host_seq = new_sequence("service-host-%d.test")
local named_route_name_seq = new_sequence("route-name-%d")
local named_route_host_seq = new_sequence("route-host-%d.test")
local acl_group_seq = new_sequence("acl-group-%d")
local jwt_key_seq = new_sequence("jwt-key-%d")
local oauth_code_seq = new_sequence("oauth-code-%d")
local keyauth_key_seq = new_sequence("keyauth-key-%d")
local hmac_username_seq = new_sequence("hmac-username-%d")
local workspace_name_seq = new_sequence("workspace-name-%d")
local key_sets_seq = new_sequence("key-sets-%d")
local keys_seq = new_sequence("keys-%d")

local random_ip = tostring(math.random(1, 255)) .. "." ..
tostring(math.random(1, 255)) .. "." ..
tostring(math.random(1, 255)) .. "." ..
tostring(math.random(1, 255))
local random_target = random_ip .. ":" .. tostring(math.random(1, 65535))

res.snis = new_blueprint(db.snis, function(overrides)
return {
name = overrides.name or sni_seq:next(),
Expand All @@ -116,7 +143,6 @@ function _M.new(db)
}
end)

local upstream_name_seq = new_sequence("upstream-%d")
windmgc marked this conversation as resolved.
Show resolved Hide resolved
res.upstreams = new_blueprint(db.upstreams, function(overrides)
local slots = overrides.slots or 100
local name = overrides.name or upstream_name_seq:next()
Expand All @@ -129,8 +155,6 @@ function _M.new(db)
}
end)

local consumer_custom_id_seq = new_sequence("consumer-id-%d")
local consumer_username_seq = new_sequence("consumer-username-%d")
res.consumers = new_blueprint(db.consumers, function()
return {
custom_id = consumer_custom_id_seq:next(),
Expand All @@ -140,8 +164,9 @@ function _M.new(db)

res.targets = new_blueprint(db.targets, function(overrides)
return {
weight = 10,
weight = overrides.weight or 10,
upstream = overrides.upstream or res.upstreams:insert(),
target = overrides.target or random_target,
}
end)

Expand Down Expand Up @@ -171,8 +196,6 @@ function _M.new(db)
}
end)

local named_service_name_seq = new_sequence("service-name-%d")
local named_service_host_seq = new_sequence("service-host-%d.test")
res.named_services = new_blueprint(db.services, function()
return {
protocol = "http",
Expand All @@ -182,8 +205,6 @@ function _M.new(db)
}
end)

local named_route_name_seq = new_sequence("route-name-%d")
local named_route_host_seq = new_sequence("route-host-%d.test")
res.named_routes = new_blueprint(db.routes, function(overrides)
return {
name = named_route_name_seq:next(),
Expand All @@ -199,7 +220,6 @@ function _M.new(db)
}
end)

local acl_group_seq = new_sequence("acl-group-%d")
res.acls = new_blueprint(db.acls, function()
return {
group = acl_group_seq:next(),
Expand Down Expand Up @@ -254,7 +274,6 @@ function _M.new(db)
}
end)

local jwt_key_seq = new_sequence("jwt-key-%d")
res.jwt_secrets = new_blueprint(db.jwt_secrets, function()
return {
key = jwt_key_seq:next(),
Expand Down Expand Up @@ -283,7 +302,6 @@ function _M.new(db)
}
end)

local oauth_code_seq = new_sequence("oauth-code-%d")
res.oauth2_authorization_codes = new_blueprint(db.oauth2_authorization_codes, function()
return {
code = oauth_code_seq:next(),
Expand All @@ -306,7 +324,6 @@ function _M.new(db)
}
end)

local keyauth_key_seq = new_sequence("keyauth-key-%d")
res.keyauth_credentials = new_blueprint(db.keyauth_credentials, function()
return {
key = keyauth_key_seq:next(),
Expand All @@ -324,7 +341,6 @@ function _M.new(db)
}
end)

local hmac_username_seq = new_sequence("hmac-username-%d")
res.hmacauth_credentials = new_blueprint(db.hmacauth_credentials, function()
return {
username = hmac_username_seq:next(),
Expand Down Expand Up @@ -360,7 +376,6 @@ function _M.new(db)
}
end)

local workspace_name_seq = new_sequence("workspace-name-%d")
res.workspaces = new_blueprint(db.workspaces, function()
return {
name = workspace_name_seq:next(),
Expand All @@ -374,13 +389,12 @@ function _M.new(db)
}
end)

local key_sets_seq = new_sequence("key-sets-%d")
res.key_sets = new_blueprint(db.key_sets, function()
return {
name = key_sets_seq:next(),
}
end)
local keys_seq = new_sequence("keys-%d")

res.keys = new_blueprint(db.keys, function()
return {
name = keys_seq:next(),
Expand Down