-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Revert "refactor(shorthand_fields): remove translate_backwards in favor of replaced_with (#13604)" #14477
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
Open
nowNick
wants to merge
1
commit into
master
Choose a base branch
from
fix/bring-back-translate-backwards
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Revert "refactor(shorthand_fields): remove translate_backwards in favor of replaced_with (#13604)" #14477
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,3 @@ | ||
message: Reverted removal of `translate_backwards` from plugins' metaschema in order to maintain backward compatibility. | ||
type: bugfix | ||
scope: Core |
This file contains hidden or 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
This file contains hidden or 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
274 changes: 274 additions & 0 deletions
274
spec/02-integration/03-db/23-shorthand_fields_translate_backwards_spec.lua
This file contains hidden or 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,274 @@ | ||
local helpers = require "spec.helpers" | ||
local cjson = require "cjson" | ||
local uuid = require("kong.tools.uuid").uuid | ||
|
||
|
||
describe("an old plugin: translate_backwards", function() | ||
local bp, db, route, admin_client | ||
local plugin_id = uuid() | ||
|
||
lazy_setup(function() | ||
helpers.test_conf.lua_package_path = helpers.test_conf.lua_package_path .. ";./spec-ee/fixtures/custom_plugins/?.lua" | ||
bp, db = helpers.get_db_utils(nil, { | ||
"plugins", | ||
}, { 'translate-backwards-older-plugin' }) | ||
|
||
route = assert(bp.routes:insert { | ||
hosts = { "redis.test" }, | ||
}) | ||
|
||
assert(helpers.start_kong({ | ||
plugins = "bundled,translate-backwards-older-plugin", | ||
nginx_conf = "spec/fixtures/custom_nginx.template", | ||
lua_package_path = "?./spec-ee/fixtures/custom_plugins/?.lua", | ||
})) | ||
|
||
admin_client = assert(helpers.admin_client()) | ||
end) | ||
|
||
lazy_teardown(function() | ||
if admin_client then | ||
admin_client:close() | ||
end | ||
|
||
helpers.stop_kong() | ||
end) | ||
|
||
describe("when creating custom plugin", function() | ||
after_each(function() | ||
db:truncate("plugins") | ||
end) | ||
|
||
describe("when using the new field", function() | ||
it("creates the custom plugin and fills in old field in response", function() | ||
-- POST | ||
local res = assert(admin_client:send { | ||
method = "POST", | ||
route = { | ||
id = route.id | ||
}, | ||
path = "/plugins", | ||
headers = { ["Content-Type"] = "application/json" }, | ||
body = { | ||
id = plugin_id, | ||
name = "translate-backwards-older-plugin", | ||
config = { | ||
new_field = "ABC" | ||
}, | ||
}, | ||
}) | ||
|
||
local json = cjson.decode(assert.res_status(201, res)) | ||
assert.same(json.config.new_field, "ABC") | ||
assert.same(json.config.old_field, "ABC") | ||
|
||
-- PATCH | ||
res = assert(admin_client:send { | ||
method = "PATCH", | ||
path = "/plugins/" .. plugin_id, | ||
headers = { ["Content-Type"] = "application/json" }, | ||
body = { | ||
name = "translate-backwards-older-plugin", | ||
config = { | ||
new_field = "XYZ" | ||
}, | ||
}, | ||
}) | ||
|
||
json = cjson.decode(assert.res_status(200, res)) | ||
assert.same(json.config.new_field, "XYZ") | ||
assert.same(json.config.old_field, "XYZ") | ||
|
||
-- GET | ||
res = assert(admin_client:send { | ||
method = "GET", | ||
path = "/plugins/" .. plugin_id | ||
}) | ||
|
||
json = cjson.decode(assert.res_status(200, res)) | ||
assert.same(json.config.new_field, "XYZ") | ||
assert.same(json.config.old_field, "XYZ") | ||
end) | ||
end) | ||
|
||
describe("when using the old field", function() | ||
it("creates the custom plugin and fills in old field in response", function() | ||
-- POST | ||
local res = assert(admin_client:send { | ||
method = "POST", | ||
route = { | ||
id = route.id | ||
}, | ||
path = "/plugins", | ||
headers = { ["Content-Type"] = "application/json" }, | ||
body = { | ||
id = plugin_id, | ||
name = "translate-backwards-older-plugin", | ||
config = { | ||
old_field = "ABC" | ||
}, | ||
}, | ||
}) | ||
|
||
local json = cjson.decode(assert.res_status(201, res)) | ||
assert.same(json.config.new_field, "ABC") | ||
assert.same(json.config.old_field, "ABC") | ||
|
||
-- PATCH | ||
res = assert(admin_client:send { | ||
method = "PATCH", | ||
path = "/plugins/" .. plugin_id, | ||
headers = { ["Content-Type"] = "application/json" }, | ||
body = { | ||
name = "translate-backwards-older-plugin", | ||
config = { | ||
old_field = "XYZ" | ||
}, | ||
}, | ||
}) | ||
|
||
json = cjson.decode(assert.res_status(200, res)) | ||
assert.same(json.config.new_field, "XYZ") | ||
assert.same(json.config.old_field, "XYZ") | ||
|
||
-- GET | ||
res = assert(admin_client:send { | ||
method = "GET", | ||
path = "/plugins/" .. plugin_id | ||
}) | ||
|
||
json = cjson.decode(assert.res_status(200, res)) | ||
assert.same(json.config.new_field, "XYZ") | ||
assert.same(json.config.old_field, "XYZ") | ||
end) | ||
end) | ||
|
||
describe("when using the both new and old fields", function() | ||
describe("when their values match", function() | ||
it("creates the custom plugin and fills in old field in response", function() | ||
-- POST | ||
local res = assert(admin_client:send { | ||
method = "POST", | ||
route = { | ||
id = route.id | ||
}, | ||
path = "/plugins", | ||
headers = { ["Content-Type"] = "application/json" }, | ||
body = { | ||
id = plugin_id, | ||
name = "translate-backwards-older-plugin", | ||
config = { | ||
new_field = "ABC", | ||
old_field = "ABC" | ||
}, | ||
}, | ||
}) | ||
|
||
local json = cjson.decode(assert.res_status(201, res)) | ||
assert.same(json.config.new_field, "ABC") | ||
assert.same(json.config.old_field, "ABC") | ||
|
||
-- PATCH | ||
res = assert(admin_client:send { | ||
method = "PATCH", | ||
path = "/plugins/" .. plugin_id, | ||
headers = { ["Content-Type"] = "application/json" }, | ||
body = { | ||
name = "translate-backwards-older-plugin", | ||
config = { | ||
new_field = "XYZ", | ||
old_field = "XYZ" | ||
}, | ||
}, | ||
}) | ||
|
||
json = cjson.decode(assert.res_status(200, res)) | ||
assert.same(json.config.new_field, "XYZ") | ||
assert.same(json.config.old_field, "XYZ") | ||
|
||
-- GET | ||
res = assert(admin_client:send { | ||
method = "GET", | ||
path = "/plugins/" .. plugin_id | ||
}) | ||
|
||
json = cjson.decode(assert.res_status(200, res)) | ||
assert.same(json.config.new_field, "XYZ") | ||
assert.same(json.config.old_field, "XYZ") | ||
end) | ||
end) | ||
|
||
describe("when their values mismatch", function() | ||
it("rejects such plugin", function() | ||
-- POST --- with mismatched values | ||
local res = assert(admin_client:send { | ||
method = "POST", | ||
route = { | ||
id = route.id | ||
}, | ||
path = "/plugins", | ||
headers = { ["Content-Type"] = "application/json" }, | ||
body = { | ||
id = plugin_id, | ||
name = "translate-backwards-older-plugin", | ||
config = { | ||
new_field = "ABC", | ||
old_field = "XYZ" | ||
}, | ||
}, | ||
}) | ||
|
||
assert.res_status(400, res) | ||
|
||
-- POST --- with correct values so that we can send PATCH below | ||
res = assert(admin_client:send { | ||
method = "POST", | ||
route = { | ||
id = route.id | ||
}, | ||
path = "/plugins", | ||
headers = { ["Content-Type"] = "application/json" }, | ||
body = { | ||
id = plugin_id, | ||
name = "translate-backwards-older-plugin", | ||
config = { | ||
new_field = "ABC", | ||
old_field = "ABC" | ||
}, | ||
}, | ||
}) | ||
|
||
local json = cjson.decode(assert.res_status(201, res)) | ||
assert.same(json.config.new_field, "ABC") | ||
assert.same(json.config.old_field, "ABC") | ||
|
||
-- PATCH | ||
res = assert(admin_client:send { | ||
method = "PATCH", | ||
path = "/plugins/" .. plugin_id, | ||
headers = { ["Content-Type"] = "application/json" }, | ||
body = { | ||
name = "translate-backwards-older-plugin", | ||
config = { | ||
new_field = "EFG", | ||
old_field = "XYZ" | ||
}, | ||
}, | ||
}) | ||
|
||
assert.res_status(400, res) | ||
|
||
-- GET | ||
res = assert(admin_client:send { | ||
method = "GET", | ||
path = "/plugins/" .. plugin_id | ||
}) | ||
|
||
json = cjson.decode(assert.res_status(200, res)) | ||
assert.same(json.config.new_field, "ABC") | ||
assert.same(json.config.old_field, "ABC") | ||
end) | ||
end) | ||
end) | ||
end) | ||
end) |
12 changes: 12 additions & 0 deletions
12
spec/fixtures/custom_plugins/kong/plugins/translate-backwards-older-plugin/handler.lua
This file contains hidden or 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,12 @@ | ||
local kong = kong | ||
|
||
local TranslateBackwardsOlderPlugin = { | ||
PRIORITY = 1000, | ||
VERSION = "0.1.0", | ||
} | ||
|
||
function TranslateBackwardsOlderPlugin:access(conf) | ||
kong.log("access phase") | ||
end | ||
|
||
return TranslateBackwardsOlderPlugin |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
would it make sense to turn this check into an early return?
I meant to highlight:
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.
I'm not sure I quite follow what you mean 🤔 - could you give me an example of this early return?
Uh oh!
There was an error while loading. Please reload this page.
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.
I meant instead of doing a long condition for the
if
maybe do:just to make it a bit more readable. I haven't thoroughly checked if this is the right logic and I'm not sure if it's a good idea here, you're more familiar with the logic to make the best decision - feel free to disregard, it's an extra minor comment.