biubiue commented on code in PR #7782:
URL: https://github.com/apache/apisix/pull/7782#discussion_r965899870


##########
t/plugin/kafka-logger.t:
##########
@@ -592,3 +592,111 @@ qr/partition_id: 2/]
 [qr/partition_id: 1/,
 qr/partition_id: 0/,
 qr/partition_id: 2/]
+
+
+
+=== TEST 20: set route(id: 1)
+--- 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": {
+                            "kafka-logger": {
+                                "broker_list" :
+                                  {
+                                    "127.0.0.1":9092
+                                  },
+                                "kafka_topic" : "test2",
+                                "key" : "key1",
+                                "timeout" : 1,
+                                "batch_max_size": 1,
+                                "sasl_config": {
+                                    "mechanism": "PLAIN",
+                                    "strategy": "sasl",
+                                    "user": "admin",
+                                    "password": "admin-secret"
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/hello"
+                }]]
+                )
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 21: access
+--- request
+GET /hello
+--- response_body
+hello world
+--- wait: 2

Review Comment:
   > we can inject the producer.new like:
   > 
   > 
https://github.com/apache/apisix/blob/2aa5c48d3acc9bea9b61958a09b51ae99c8a528b/t/plugin/tencent-cloud-cls.t#L220-L236
   Em, like this?
   `=== TEST 20: create producer with sasl_config`
   `--- extra_init_by_lua`
       `local producer = require("resty.kafka.producer")`
       `local klogger = 
require("apisix.plugins.kafka-logger")`
       `producer.new = function(klogger)`
           `if  (!klogger.sasl_config)  
then`
   
            `ngx.say("create
 producer without sasl_config")`
   
            `return 
producer`
           `end`
           `producer.sasl_config = 
klogger.sasl_config`
           `ngx.say("create producer 
with sasl_config")`
           `return producer`
       `end`
   `--- request`
   `GET /hello`
   `--- response_body`
   `hello world`
   `--- wait: 2`



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