Skip to content

Commit

Permalink
spec
Browse files Browse the repository at this point in the history
  • Loading branch information
liverpool8056 committed May 18, 2023
1 parent a08f111 commit 166112c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ jobs:
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 8
cassandra:
image: cassandra:3
ports:
- 7199:7199
- 7000:7000
- 9160:9160
- 9042:9042
options: --health-cmd "cqlsh -e 'describe cluster'" --health-interval 5s --health-timeout 5s --health-retries 8

steps:
- name: Checkout Kong source code
Expand Down
6 changes: 2 additions & 4 deletions spec/01-unit/19-hybrid/03-compat_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,11 @@ describe("kong.clustering.compat", function()
end)

for _, strategy in helpers.each_strategy() do
describe("check compat for entities those have `updated_at` field", function()
describe("[#" .. strategy .. "]: check compat for entities those have `updated_at` field", function()
local bp, db, entity_names

setup(function()
-- excludes entities are not exported: clustering_data_planes, document_objects, files,
-- group_rbac_roles, groups, legacy_files, login_attempts, rbac_role_endpoints,
-- rbac_role_entities, rbac_roles, rbac_users
-- excludes entities not exportable: clustering_data_planes,
entity_names = {
"services",
"routes",
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")
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

0 comments on commit 166112c

Please sign in to comment.