This is an automated email from the ASF dual-hosted git repository.
chenjunxu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new e74674649 chore(grpc-transcode): adjust the position of enums in
pb_option_def (#11448)
e74674649 is described below
commit e74674649fde29cc59ae70be1f8a6f2266b3ba40
Author: Billy Zhou <[email protected]>
AuthorDate: Mon Aug 5 14:59:14 2024 +0800
chore(grpc-transcode): adjust the position of enums in pb_option_def
(#11448)
---
apisix/plugins/grpc-transcode.lua | 4 ++--
t/plugin/grpc-transcode3.t | 43 +++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/apisix/plugins/grpc-transcode.lua
b/apisix/plugins/grpc-transcode.lua
index a89008d39..625018fb7 100644
--- a/apisix/plugins/grpc-transcode.lua
+++ b/apisix/plugins/grpc-transcode.lua
@@ -27,11 +27,11 @@ local plugin_name = "grpc-transcode"
local pb_option_def = {
{ description = "enum as result",
type = "string",
- enum = {"int64_as_number", "int64_as_string", "int64_as_hexstring"},
+ enum = {"enum_as_name", "enum_as_value"},
},
{ description = "int64 as result",
type = "string",
- enum = {"enum_as_name", "enum_as_value"},
+ enum = {"int64_as_number", "int64_as_string", "int64_as_hexstring"},
},
{ description ="default values option",
type = "string",
diff --git a/t/plugin/grpc-transcode3.t b/t/plugin/grpc-transcode3.t
index 0a8ddf54d..93a3d6267 100644
--- a/t/plugin/grpc-transcode3.t
+++ b/t/plugin/grpc-transcode3.t
@@ -576,3 +576,46 @@ location /t {
}
--- response_body
passed
+
+
+
+=== TEST 14: pb_option - check the matchings between enum and category
+--- config
+ location /t {
+ content_by_lua_block {
+ local ngx_re_match = ngx.re.match
+ local plugin = require("apisix.plugins.grpc-transcode")
+
+ local pb_option_def =
plugin.schema.properties.pb_option.items.anyOf
+
+ local patterns = {
+ [[^enum_as_.+$]],
+ [[^int64_as_.+$]],
+ [[^.+_default_.+$]],
+ [[^.+_hooks$]],
+ }
+
+ local function check_pb_option_enum_category()
+ for i, category in ipairs(pb_option_def) do
+ for _, enum in ipairs(category.enum) do
+ if not ngx_re_match(enum, patterns[i], "jo") then
+ return ([[mismatch between enum("%s") and
category("%s")]]):format(
+ enum, category.description)
+ end
+ end
+ end
+ end
+
+ local err = check_pb_option_enum_category()
+ if err then
+ ngx.say(err)
+ return
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done