Skip to content

Commit

Permalink
fix: plugin metadata missing v3 adapter call (#7877)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 authored Sep 8, 2022
1 parent c397ede commit a624339
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 69 deletions.
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}

0 comments on commit a624339

Please sign in to comment.