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

fix: plugin metadata missing v3 adapter call #7877

Merged
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
1 change: 1 addition & 0 deletions apisix/admin/plugin_metadata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local utils = require("apisix.admin.utils")

local injected_mark = "injected metadata_schema"
local _M = {
need_v3_filter = true,
}


Expand Down
110 changes: 45 additions & 65 deletions t/admin/plugin-metadata.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ __DATA__
"ikey": 1
}]],
[[{
"node": {
"value": {
"skey": "val",
"ikey": 1
}
}
"value": {
"skey": "val",
"ikey": 1
},
"key": "/apisix/plugin_metadata/example-plugin"
}]]
)
)

ngx.status = code
ngx.say(body)
Expand All @@ -72,14 +71,12 @@ passed
"ikey": 2
}]],
[[{
"node": {
"value": {
"skey": "val2",
"ikey": 2
}
"value": {
"skey": "val2",
"ikey": 2
}
}]]
)
)

ngx.status = code
ngx.say(body)
Expand All @@ -92,14 +89,12 @@ passed
"ikey": 2
}]],
[[{
"node": {
"value": {
"skey": "val2",
"ikey": 2
}
"value": {
"skey": "val2",
"ikey": 2
}
}]]
)
)

ngx.say(code)
ngx.say(body)
Expand All @@ -125,14 +120,12 @@ passed
ngx.HTTP_GET,
nil,
[[{
"node": {
"value": {
"skey": "val2",
"ikey": 2
}
"value": {
"skey": "val2",
"ikey": 2
}
}]]
)
)

ngx.status = code
ngx.say(body)
Expand All @@ -153,9 +146,7 @@ passed
content_by_lua_block {
ngx.sleep(0.3)
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/plugin_metadata/example-plugin',
ngx.HTTP_DELETE
)
local code, body = t('/apisix/admin/plugin_metadata/example-plugin', ngx.HTTP_DELETE)

ngx.status = code
ngx.say(body)
Expand All @@ -175,9 +166,7 @@ passed
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code = t('/apisix/admin/plugin_metadata/not_found',
ngx.HTTP_DELETE
)
local code = t('/apisix/admin/plugin_metadata/not_found', ngx.HTTP_DELETE)
ngx.say("[delete] code: ", code)
}
}
Expand All @@ -196,14 +185,12 @@ GET /t
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/plugin_metadata',
ngx.HTTP_PUT,
[[{"k": "v"}]],
ngx.HTTP_PUT,
[[{"k": "v"}]],
[[{
"node": {
"value": "sdf"
}
"value": "sdf"
}]]
)
)

ngx.status = code
ngx.print(body)
Expand All @@ -225,14 +212,12 @@ GET /t
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/plugin_metadata/test',
ngx.HTTP_PUT,
[[{"k": "v"}]],
ngx.HTTP_PUT,
[[{"k": "v"}]],
[[{
"node": {
"value": "sdf"
}
"value": "sdf"
}]]
)
)

ngx.status = code
ngx.print(body)
Expand All @@ -259,14 +244,12 @@ GET /t
"skey": "val"
}]],
[[{
"node": {
"value": {
"skey": "val",
"ikey": 1
}
"value": {
"skey": "val",
"ikey": 1
}
}]]
)
)

ngx.status = code
ngx.say(body)
Expand All @@ -289,12 +272,12 @@ qr/\{"error_msg":"invalid configuration: property \\"ikey\\" is required"\}/
local json = require("toolkit.json")
local t = require("lib.test_admin").test
local code, message, res = t('/apisix/admin/plugin_metadata/example-plugin',
ngx.HTTP_PUT,
ngx.HTTP_PUT,
[[{
"skey": "val",
"ikey": 1
}]]
)
)

if code >= 300 then
ngx.status = code
Expand All @@ -303,13 +286,11 @@ qr/\{"error_msg":"invalid configuration: property \\"ikey\\" is required"\}/
end

res = json.decode(res)
res.node.value.create_time = nil
res.node.value.update_time = nil
ngx.say(json.encode(res))
}
}
--- response_body
{"node":{"key":"/apisix/plugin_metadata/example-plugin","value":{"ikey":1,"skey":"val"}}}
{"key":"/apisix/plugin_metadata/example-plugin","value":{"ikey":1,"skey":"val"}}
--- request
GET /t
--- no_error_log
Expand All @@ -323,9 +304,7 @@ GET /t
content_by_lua_block {
local json = require("toolkit.json")
local t = require("lib.test_admin").test
local code, message, res = t('/apisix/admin/plugin_metadata/example-plugin',
ngx.HTTP_GET
)
local code, message, res = t('/apisix/admin/plugin_metadata/example-plugin', ngx.HTTP_GET)

if code >= 300 then
ngx.status = code
Expand All @@ -334,14 +313,17 @@ GET /t
end

res = json.decode(res)
local value = res.node.value
assert(res.count ~= nil)
res.count = nil

assert(res.createdIndex ~= nil)
res.createdIndex = nil
assert(res.modifiedIndex ~= nil)
res.modifiedIndex = nil

ngx.say(json.encode(res))
}
}
--- response_body
{"node":{"key":"/apisix/plugin_metadata/example-plugin","value":{"ikey":1,"skey":"val"}}}
{"key":"/apisix/plugin_metadata/example-plugin","value":{"ikey":1,"skey":"val"}}
--- request
GET /t
--- no_error_log
Expand All @@ -355,9 +337,7 @@ GET /t
content_by_lua_block {
local json = require("toolkit.json")
local t = require("lib.test_admin").test
local code, message, res = t('/apisix/admin/plugin_metadata/example-plugin',
ngx.HTTP_DELETE
)
local code, message, res = t('/apisix/admin/plugin_metadata/example-plugin', ngx.HTTP_DELETE)

if code >= 300 then
ngx.status = code
Expand All @@ -370,7 +350,7 @@ GET /t
}
}
--- response_body
{"deleted":"1","key":"/apisix/plugin_metadata/example-plugin","node":{}}
{"deleted":"1","key":"/apisix/plugin_metadata/example-plugin"}
--- request
GET /t
--- no_error_log
Expand Down
6 changes: 2 additions & 4 deletions t/admin/plugin-metadata2.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ __DATA__
local json = require("toolkit.json")
local t = require("lib.test_admin").test

local code, message, res = t('/apisix/admin/plugin_metadata',
ngx.HTTP_GET
)
local code, message, res = t('/apisix/admin/plugin_metadata', ngx.HTTP_GET)

if code >= 300 then
ngx.status = code
Expand All @@ -60,4 +58,4 @@ __DATA__
}
}
--- response_body
{"count":0,"list":[]}
{"list":[],"total":0}