nic-6443 commented on code in PR #13358:
URL: https://github.com/apache/apisix/pull/13358#discussion_r3393074770


##########
t/plugin/limit-count5.t:
##########
@@ -307,3 +307,47 @@ peek3: 3
 commit2: 0
 peek4: 0
 commit3: rejected
+
+
+
+=== TEST 9: error() call in gen_limit_key produces correct error message when 
parent is missing
+--- config
+    location /t {
+        content_by_lua_block {
+            local init = require("apisix.plugins.limit-count.init")
+            local conf = {
+                policy = "local",
+                count = 5,
+                time_window = 60,
+                key = "remote_addr",
+                key_type = "var",
+                rejected_code = 503,
+                allow_degradation = false,
+                show_limit_quota_header = true,
+                _meta = {}
+                -- _meta.parent is intentionally missing
+            }
+            local ctx = {
+                var = {remote_addr = "127.0.0.1"},
+                conf_version = 1,
+                conf_type = "route"
+            }
+            local ok, err = pcall(init.rate_limit, conf, ctx, "limit-count", 1)
+            if not ok then
+                -- error message should contain the JSON of parent (null)
+                if err:find("failed to generate key invalid parent") then

Review Comment:
   The comment on the line above says the message should contain the JSON of 
parent, but the assertion only checks the prefix `failed to generate key 
invalid parent` — which would pass even if the `.. core.json.encode(parent)` 
part got lost. Since gluing the encoded parent onto the message is exactly what 
this PR changes, I'd assert the full message, e.g. `err:find("failed to 
generate key invalid parent: null", 1, true)`, so the test also locks in that 
`core.json.encode(nil)` ends up in the output.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to