Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
raoxiaoyan committed Jun 25, 2024
1 parent e6f8466 commit 2121263
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions spec/02-integration/03-db/14-dao_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ for _, strategy in helpers.all_strategies() do
"services",
"consumers",
"acls",
"keyauth_credentials",
})
_G.kong.db = db

Expand Down Expand Up @@ -98,6 +99,7 @@ for _, strategy in helpers.all_strategies() do
db.consumers:truncate()
db.plugins:truncate()
db.services:truncate()
db.keyauth_credentials:truncate()
end)

it("select_by_cache_key()", function()
Expand Down Expand Up @@ -185,6 +187,33 @@ for _, strategy in helpers.all_strategies() do
assert.same(new_plugin_config.config.redis.host, read_plugin.config.redis.host)
assert.same(new_plugin_config.config.redis.host, read_plugin.config.redis_host) -- legacy field is included
end)

it("keyauth_credentials can be deleted or selected before run ttl cleanup in background timer", function()
local b_keyauth_credentials = bp.keyauth_credentials:insert({
consumer = { id = consumer.id },
}, { ttl = 5 })

-- wait for 5 seconds.
ngx.sleep(5)

-- select or delete keyauth_credentials after ttl expired.

local expired_keyauth_credentials = bp.keyauth_credentials:select({ consumer = { id = consumer.id } })
assert.is_nil(expired_keyauth_credentials)
bp.keyauth_credentials:delete({ consumer = { id = consumer.id } })

-- select or delete keyauth_credentials with skip_ttl=true after ttl expired.
expired_keyauth_credentials = bp.keyauth_credentials:select({ consumer = { id = consumer.id } },
{ skip_ttl = true })
assert.not_nil(expired_keyauth_credentials)
assert.same(expired_keyauth_credentials.id, b_keyauth_credentials.id)
bp.keyauth_credentials:delete({ consumer = { id = consumer.id } }, { skip_ttl = true })

-- check again
expired_keyauth_credentials = bp.keyauth_credentials:select({ consumer = { id = consumer.id } },
{ skip_ttl = true })
assert.is_nil(expired_keyauth_credentials)
end)
end)
end

0 comments on commit 2121263

Please sign in to comment.