monkeyDluffy6017 commented on code in PR #9712:
URL: https://github.com/apache/apisix/pull/9712#discussion_r1254297795


##########
t/plugin/file-logger2.t:
##########
@@ -274,3 +274,95 @@ passed
     }
 --- response_body
 write file log success
+
+=== TEST 8: Add new configuration with vars_match
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                        "plugins": {
+                            "file-logger": {
+                                "path": "file-with-vars_match.log",
+                                "vars": [
+                                    [
+                                        [ "arg_name","==","jack" ]
+                                    ]
+                                ],
+                                "log_format": {
+                                    "request": "$request"
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1982": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/hello"
+                }]]
+            )
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+=== TEST 9: Request matches vars_match
+--- config
+    location /t {
+        content_by_lua_block {
+            local core = require("apisix.core")
+            local t = require("lib.test_admin").test
+            local code = t("/hello?name=jack", ngx.HTTP_GET)
+            local fd, err = io.open("file-with-vars_match.log", 'r')
+            local msg
+
+            if not fd then
+                core.log.error("failed to open file: file-with-vars_match.log, 
error info: ", err)
+                return
+            end
+
+            msg = fd:read()
+
+            local new_msg = core.json.decode(msg)
+            if new_msg.request == 'GET /hello?name=jack HTTP/1.1' 
+                and new_msg.route_id == '1'
+            then
+                msg = "write file log success"
+                ngx.status = code
+                ngx.say(msg)
+            end
+
+            os.remove("file-with-vars_match.log")
+        }
+    }
+--- response_body
+write file log success
+
+
+=== TEST 10: Request not matches vars_match

Review Comment:
   Ditto



-- 
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