Revolyssup commented on code in PR #9526:
URL: https://github.com/apache/apisix/pull/9526#discussion_r1208918150


##########
t/plugin/splunk-hec-logging.t:
##########
@@ -224,157 +224,135 @@ hello world
 --- config
     location /t {
         content_by_lua_block {
-            local config = {
+            local t = require("lib.test_admin").test
+            local code, body = 
t('/apisix/admin/plugin_metadata/splunk-hec-logging',
+                 ngx.HTTP_PUT,
+                 [[{
+                        "log_format": {
+                            "host": "$host",
+                            "@timestamp": "$time_iso8601",
+                            "client_ip": "$remote_addr",
+                            "message_1":"test custom log format in plugin"
+                        }
+                }]]
+                )
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+            local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, {
                 uri = "/hello",
                 upstream = {
                     type = "roundrobin",
                     nodes = {
-                        ["127.0.0.1:1980"] = 1
+                        ["127.0.0.1:1982"] = 1
                     }
                 },
                 plugins = {
                     ["splunk-hec-logging"] = {
                         endpoint = {
-                            uri = "http://127.0.0.1:1980/splunk_hec_logging";,
+                            uri = "http://127.0.0.1:18088/services/collector";,
                             token = "BD274822-96AA-4DA6-90EC-18940FB2414C"
                         },
-                        batch_max_size = 1,
+                        batch_max_size = 3,
                         inactive_timeout = 1
                     }
                 }
-            }
-            local t = require("lib.test_admin").test
-            local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, 
config)
-
+            })
             if code >= 300 then
                 ngx.status = code
                 ngx.say(body)
                 return
             end
-
-            local code, body = 
t('/apisix/admin/plugin_metadata/splunk-hec-logging',
-                 ngx.HTTP_PUT,
-                 [[{
-                        "log_format": {
-                            "host": "$host",
-                            "@timestamp": "$time_iso8601",
-                            "client_ip": "$remote_addr"
-                        }
-                }]]
-                )
+            local code, _, body2 = t("/hello", "GET")
             if code >= 300 then
                 ngx.status = code
-                ngx.say(body)
+                ngx.say("fail")
                 return
             end
             ngx.say(body)
         }
     }
+--- wait: 0.5
 --- response_body
 passed
 
 
 
-=== TEST 8: hit
---- extra_init_by_lua
-    local core = require("apisix.core")
-    local decode = require("toolkit.json").decode
-    local up = require("lib.server")
-    up.splunk_hec_logging = function()
-        ngx.log(ngx.WARN, "the mock backend is hit")
-
-        ngx.req.read_body()
-        local data = ngx.req.get_body_data()
-        ngx.log(ngx.WARN, data)
-        data = decode(data)
-        assert(data.event.client_ip == "127.0.0.1")
-        assert(data.source == "apache-apisix-splunk-hec-logging")
-        assert(data.host == core.utils.gethostname())
-        ngx.say('{}')
-    end
---- request
-GET /hello
---- wait: 2
---- response_body
-hello world
---- error_log
-the mock backend is hit
---- no_error_log
-[error]
+=== TEST 8: check splunk log
+--- exec
+tail -n 1 ci/pod/vector/splunk.log
+--- response_body eval
+qr/.*test custom log format in plugin.*/
 
 
 
 === TEST 9: set route to test custom log format in route
 --- config
     location /t {
         content_by_lua_block {
-            local config = {
+            local t = require("lib.test_admin").test
+            local code, body = 
t('/apisix/admin/plugin_metadata/splunk-hec-logging',
+                 ngx.HTTP_PUT,
+                 [[{
+                        "log_format": {
+                            "host": "$host",
+                            "@timestamp": "$time_iso8601",
+                            "vip": "$remote_addr",
+                            "message_2":"logger format in plugin"
+                        }
+                }]]
+                )
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+            local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, {

Review Comment:
   Added newline at all suggested place @monkeyDluffy6017 



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