spacewander commented on a change in pull request #4863:
URL: https://github.com/apache/apisix/pull/4863#discussion_r696212065



##########
File path: t/plugin/kafka-logger.t
##########
@@ -725,41 +725,179 @@ qr/partition_id: 2/]
 
 
 
-=== TEST 20: error log, failed to identify the broker specified
+=== TEST 20: required_acks, matches none of the enum values
 --- 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" : {},
-                                    "kafka_topic" : "test"
-                             }
+            local plugin = require("apisix.plugins.kafka-logger")
+            local ok, err = plugin.check_schema({
+                broker_list = {
+                    ["127.0.0.1"] = 3000
+                },
+                required_acks = 10,
+                kafka_topic ="test",
+                key= "key1"
+            })
+            if not ok then
+                ngx.say(err)
+            end
+            ngx.say("done")
+        }
+    }
+--- request
+GET /t
+--- response_body
+property "required_acks" validation failed: matches none of the enum values
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 21: report log to kafka, with required_acks(1, 0, -1)
+--- config
+location /t {
+    content_by_lua_block {
+        local data = {
+            {
+                input = {
+                    plugins = {
+                        ["kafka-logger"] = {
+                            broker_list = {
+                                ["127.0.0.1"] = 9092
+                            },
+                            kafka_topic = "test2",
+                            producer_type = "sync",
+                            timeout = 1,
+                            batch_max_size = 1,
+                            required_acks = 1,
+                            meta_format = "origin",
+                        }
+                    },
+                    upstream = {
+                        nodes = {
+                            ["127.0.0.1:1980"] = 1
                         },
-                        "upstream": {
-                            "nodes": {
-                                "127.0.0.1:1980": 1
+                        type = "roundrobin"
+                    },
+                    uri = "/hello",
+                },
+            },
+            {
+                input = {
+                    plugins = {
+                        ["kafka-logger"] = {
+                            broker_list = {
+                                ["127.0.0.1"] = 9092
                             },
-                            "type": "roundrobin"
+                            kafka_topic = "test2",
+                            producer_type = "sync",
+                            timeout = 1,
+                            batch_max_size = 1,
+                            required_acks = -1,
+                            meta_format = "origin",
+                        }
+                    },
+                    upstream = {
+                        nodes = {
+                            ["127.0.0.1:1980"] = 1
                         },
-                        "uri": "/hello"
-                }]]
-                )
+                        type = "roundrobin"
+                    },
+                    uri = "/hello",
+                },
+            },
+            {
+                input = {
+                    plugins = {
+                        ["kafka-logger"] = {
+                            broker_list = {
+                                ["127.0.0.1"] = 9092
+                            },
+                            kafka_topic = "test2",
+                            producer_type = "sync",
+                            timeout = 1,
+                            batch_max_size = 1,
+                            required_acks = 0,
+                            meta_format = "origin",
+                        }
+                    },
+                    upstream = {
+                        nodes = {
+                            ["127.0.0.1:1980"] = 1
+                        },
+                        type = "roundrobin"
+                    },
+                    uri = "/hello",
+                },
+            },
+        }
+
+        local t = require("lib.test_admin").test
+        local err_count = 0
+        for i in ipairs(data) do
+            local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, 
data[i].input)
+
             if code >= 300 then
-                ngx.status = code
+                err_count = err_count + 1
             end
-            ngx.say(body)
+            ngx.print(body)
 
-            local http = require "resty.http"
-            local httpc = http.new()
-            local uri = "http://127.0.0.1:"; .. ngx.var.server_port .. "/hello"
-            local res, err = httpc:request_uri(uri, {method = "GET"})
+            t('/hello', ngx.HTTP_GET)
+        end
+
+        assert(err_count == 0)
+    }
+}
+--- request
+GET /t
+--- no_error_log
+[error]
+--- error_log
+send data to kafka: GET /hello
+send data to kafka: GET /hello
+send data to kafka: GET /hello
+
+
+
+=== TEST 22: schema check, broker_list is {}
+--- config
+    location /t {
+        content_by_lua_block {
+            local plugin = require("apisix.plugins.kafka-logger")
+            local ok, err = plugin.check_schema({broker_list = {}, kafka_topic 
= "test", key= "key1"})
+            if not ok then
+                ngx.say(err)
+            end
+            ngx.say("done")
         }
     }
 --- request
 GET /t
---- error_log_like eval
-qr/failed to identify the broker specified/
+--- response_body
+property "broker_list" validation failed: expect object to have at least 1 
properties
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 23: schema check, wrong kafka port type
+--- config
+    location /t {
+        content_by_lua_block {
+            local plugin = require("apisix.plugins.kafka-logger")
+            local ok, err = plugin.check_schema({broker_list = {["127.0.0.1"] 
= "9092"}, kafka_topic = "test", key= "key1"})

Review comment:
       Could we merge the borker_list check into one test case?




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