-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(plugins): add old version plugin compatibility test (#9077)
Test the old version plugin against the latest core code. We only focus on whether there is any runtime error in the happy path. Because logic changes from version to version, it is not feasible to test the behavior of the plugin. This test is not guaranteed to capture all interface changes, because it may not be able to cover all the dependent interfaces, and even if the interface is covered, it can't detect interface semantic changes or internal logic changes. These kinds of things still rely on the tests of the interfaces themselves to cover. https://konghq.atlassian.net/browse/FTI-5923
- Loading branch information
Showing
3 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
spec/03-plugins/03-http-log/05-old-plugin-compatibility_spec.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
-- This software is copyright Kong Inc. and its licensors. | ||
-- Use of the software is subject to the agreement between your organization | ||
-- and Kong Inc. If there is no such agreement, use is governed by and | ||
-- subject to the terms of the Kong Master Software License Agreement found | ||
-- at https://konghq.com/enterprisesoftwarelicense/. | ||
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ] | ||
|
||
local helpers = require "spec.helpers" | ||
local fmt = string.format | ||
local plugin_name = "http-log" | ||
|
||
for _, strategy in helpers.all_strategies() do | ||
describe(fmt("%s - old plugin compatibility [#%s]", plugin_name, strategy), function() | ||
local bp, proxy_client, yaml_file | ||
local recover_new_plugin | ||
|
||
lazy_setup(function() | ||
-- use the old version plugin | ||
recover_new_plugin = helpers.use_old_plugin(plugin_name) | ||
|
||
bp = helpers.get_db_utils(strategy == "off" and "postgres" or strategy, { | ||
"routes", | ||
"services", | ||
"plugins", | ||
}) | ||
|
||
local route = bp.routes:insert({ paths = { "/test" } }) | ||
|
||
bp.plugins:insert({ | ||
name = plugin_name, | ||
route = { id = route.id }, | ||
config = { | ||
http_endpoint = fmt("http://%s:%s/post_log/http", helpers.mock_upstream_host, helpers.mock_upstream_port), | ||
custom_fields_by_lua = { | ||
new_field = "return 123", | ||
route = "return nil", -- unset route field | ||
}, | ||
}, | ||
}) | ||
|
||
if strategy == "off" then | ||
yaml_file = helpers.make_yaml_file() | ||
end | ||
|
||
assert(helpers.start_kong({ | ||
database = strategy, | ||
nginx_conf = "spec/fixtures/custom_nginx.template", | ||
declarative_config = strategy == "off" and yaml_file or nil, | ||
pg_host = strategy == "off" and "unknownhost.konghq.com" or nil, | ||
})) | ||
end) | ||
|
||
lazy_teardown(function() | ||
helpers.stop_kong() | ||
-- recover the new version plugin | ||
recover_new_plugin() | ||
end) | ||
|
||
before_each(function() | ||
helpers.clean_logfile() | ||
proxy_client = helpers.proxy_client() | ||
end) | ||
|
||
after_each(function() | ||
if proxy_client then | ||
proxy_client:close() | ||
end | ||
end) | ||
|
||
it("should not throw exception when using old version plugin together with the new core", function() | ||
local res = assert(proxy_client:send { | ||
method = "GET", | ||
path = "/test", | ||
}) | ||
assert.not_same(500, res.status) | ||
|
||
-- wait for the log handler to execute | ||
ngx.sleep(5) | ||
|
||
assert.logfile().has.no.line("[error]", true, 0) | ||
assert.logfile().has.no.line("[alert]", true, 0) | ||
assert.logfile().has.no.line("[crit]", true, 0) | ||
assert.logfile().has.no.line("[emerg]", true, 0) | ||
end) | ||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c2860b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bazel Build
Docker image available
kong/kong:c2860b1af2aba6e40bd0a66576fecb4c53f857d4
Artifacts available https://github.com/Kong/kong/actions/runs/10365030543