Skip to content

Commit

Permalink
ci: tcp-logger remove mock test case
Browse files Browse the repository at this point in the history
Signed-off-by: Sn0rt <wangguohao.2009@gmail.com>
  • Loading branch information
Sn0rt committed May 5, 2023
1 parent 983b03f commit c119606
Showing 1 changed file with 58 additions and 80 deletions.
138 changes: 58 additions & 80 deletions t/plugin/tcp-logger.t
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ done
"plugins": {
"tcp-logger": {
"host": "127.0.0.1",
"port": 5044,
"port": 3000,
"tls": false
}
},
Expand Down Expand Up @@ -134,6 +134,7 @@ hello world


=== TEST 6: error log
--- log_level: error
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -192,7 +193,7 @@ failed to connect to TCP server: host[312.0.0.1] port[2000]
"plugins": {
"tcp-logger": {
"host": "127.0.0.1",
"port": 5044,
"port": 3000,
"tls": false,
"batch_max_size": 1
}
Expand Down Expand Up @@ -226,7 +227,7 @@ failed to connect to TCP server: host[312.0.0.1] port[2000]
"plugins": {
"tcp-logger": {
"host": "127.0.0.1",
"port": 5045,
"port": 43000,
"tls": false,
"batch_max_size": 1
}
Expand Down Expand Up @@ -269,8 +270,8 @@ passedopentracing
--- grep_error_log eval
qr/sending a batch logs to 127.0.0.1:(\d+)/
--- grep_error_log_out
sending a batch logs to 127.0.0.1:5044
sending a batch logs to 127.0.0.1:5045
sending a batch logs to 127.0.0.1:3000
sending a batch logs to 127.0.0.1:43000



Expand Down Expand Up @@ -312,7 +313,7 @@ GET /t
"plugins": {
"tcp-logger": {
"host": "127.0.0.1",
"port": 8125,
"port": 3000,
"tls": false,
"batch_max_size": 1,
"inactive_timeout": 1
Expand All @@ -338,6 +339,7 @@ GET /t
ngx.HTTP_PUT,
[[{
"log_format": {
"case name": "plugin_metadata",
"host": "$host",
"@timestamp": "$time_iso8601",
"client_ip": "$remote_addr"
Expand All @@ -349,7 +351,15 @@ GET /t
ngx.say(body)
return
end
ngx.say(body)

local code, _, _ = t("/hello", "GET")
if code >= 300 then
ngx.status = code
ngx.say("fail")
return
end

ngx.say("passed")
}
}
--- request
Expand All @@ -359,47 +369,38 @@ passed



=== TEST 10: access
--- stream_conf_enable
--- extra_stream_config
server {
listen 8125;
content_by_lua_block {
local decode = require("toolkit.json").decode
ngx.log(ngx.WARN, "the mock backend is hit")
=== TEST 10: log format in plugin_metadata
--- exec
tail -n 1 ci/pod/vector/tcp.log
--- response_body eval
qr/.*plugin_metadata.*/

local sock, err = ngx.req.socket(true)
if not sock then
ngx.log(ngx.ERR, "failed to get the request socket: ", err)
return
end

local data, err = sock:receive('*a')

if not data then
if err and err ~= "closed" then
ngx.log(ngx.ERR, "socket error, returning: ", err)
end
return
end
=== TEST 11: remove tcp logger metadata
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test

local code, body = t('/apisix/admin/plugin_metadata/tcp-logger',
ngx.HTTP_PUT,
[[{
"log_format": {}
}]]
)

data = decode(data)
assert(data.client_ip == "127.0.0.1")
ngx.say(body)
}
}
--- request
GET /hello
GET /t
--- response_body
hello world
--- wait: 2
--- error_log
the mock backend is hit
--- no_error_log
[error]
passed



=== TEST 11: log format in plugin
=== TEST 12: log format in plugin
--- config
location /t {
content_by_lua_block {
Expand All @@ -410,9 +411,10 @@ the mock backend is hit
"plugins": {
"tcp-logger": {
"host": "127.0.0.1",
"port": 8125,
"port": 3000,
"tls": false,
"log_format": {
"case name": "logger format in plugin",
"vip": "$remote_addr"
},
"batch_max_size": 1,
Expand All @@ -435,57 +437,33 @@ the mock backend is hit
return
end

ngx.say(body)
local code, _, body2 = t("/hello", "GET")
if code >= 300 then
ngx.status = code
ngx.say("fail")
return
end

ngx.say("passed")
}
}
--- request
GET /t
--- wait: 0.5
--- response_body
passed



=== TEST 12: access
--- stream_conf_enable
--- extra_stream_config
server {
listen 8125;
content_by_lua_block {
local decode = require("toolkit.json").decode
ngx.log(ngx.WARN, "the mock backend is hit")

local sock, err = ngx.req.socket(true)
if not sock then
ngx.log(ngx.ERR, "failed to get the request socket: ", err)
return
end

local data, err = sock:receive('*a')

if not data then
if err and err ~= "closed" then
ngx.log(ngx.ERR, "socket error, returning: ", err)
end
return
end

data = decode(data)
assert(data.vip == "127.0.0.1")
}
}
--- request
GET /hello
--- response_body
hello world
--- wait: 2
--- error_log
the mock backend is hit
--- no_error_log
[error]
=== TEST 13: check tcp log
--- exec
tail -n 1 ci/pod/vector/tcp.log
--- response_body eval
qr/.*logger format in plugin.*/



=== TEST 13: true tcp log without tls
=== TEST 14: true tcp log without tls
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -535,15 +513,15 @@ opentracing



=== TEST 14: check tcp log
=== TEST 15: check tcp log
--- exec
tail -n 1 ci/pod/vector/tcp.log
--- response_body eval
qr/.*route_id.*1.*/



=== TEST 15: true tcp log with tls
=== TEST 16: true tcp log with tls
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -593,7 +571,7 @@ opentracing



=== TEST 16: check tls log
=== TEST 17: check tls log
--- exec
tail -n 1 ci/pod/vector/tls-datas.log
--- response_body eval
Expand Down

0 comments on commit c119606

Please sign in to comment.