monkeyDluffy6017 commented on code in PR #9712:
URL: https://github.com/apache/apisix/pull/9712#discussion_r1261516413
##########
t/plugin/file-logger2.t:
##########
@@ -274,3 +274,100 @@ passed
}
--- response_body
write file log success
+
+
+
+=== TEST 8: Add new configuration with matches
+--- 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-matches.log",
+ "matches": [
+ [
+ [ "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
+--- 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-matches.log", 'r')
+ local msg
+
+ if not fd then
+ core.log.error("failed to open file: file-with-matches.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-matches.log")
+ }
+ }
+--- response_body
+write file log success
+
+
+
+=== TEST 10: Request not matches matches
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code = t("/hello?name=tony", ngx.HTTP_GET)
+ local fd, err = io.open("file-with-matches.log", 'r')
+ local msg
+
+ if not fd then
+ msg = "not write file log"
+ ngx.say(msg)
+ return
+ end
Review Comment:
```suggestion
local code = t("/hello?name=tony", ngx.HTTP_GET)
local fd, err = io.open("file-with-matches.log", 'r')
if not fd then
local msg = "not write file log"
ngx.say(msg)
return
end
```
--
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]