From 8f0d25578aecef83adecf44021b5cb069ba815dc Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 10 Oct 2023 18:50:31 +0800 Subject: [PATCH] test case --- src/ngx_http_lua_kong_request_id.c | 2 +- t/010-request-id.t | 40 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 t/010-request-id.t diff --git a/src/ngx_http_lua_kong_request_id.c b/src/ngx_http_lua_kong_request_id.c index 5c010456..48df2312 100644 --- a/src/ngx_http_lua_kong_request_id.c +++ b/src/ngx_http_lua_kong_request_id.c @@ -19,7 +19,7 @@ #define KONG_REQUEST_ID_MAX_LEN 16 -#define KONG_REQUEST_ID_FORMAT "%08x%08x" +#define KONG_REQUEST_ID_FORMAT "%08xD%08xD" static ngx_int_t diff --git a/t/010-request-id.t b/t/010-request-id.t new file mode 100644 index 00000000..a8adf4ba --- /dev/null +++ b/t/010-request-id.t @@ -0,0 +1,40 @@ +# vim:set ft= ts=4 sw=4 et: + +use Test::Nginx::Socket::Lua; +use Cwd qw(cwd); + +plan tests => repeat_each() * (blocks() * 5); + +my $pwd = cwd(); + +$ENV{TEST_NGINX_HTML_DIR} ||= html_dir(); + +no_long_string(); +#no_diff(); + +run_tests(); + +__DATA__ + +=== TEST 1: $kong_request_id works +--- config + location /t { + content_by_lua_block { + local rid = ngx.var.kong_request_id + assert(ngx.re.match(rid, "[0-9a-f]{16}")) + ngx.say("ok") + } + } + +--- request +GET /t +--- response_body_like +ok + +--- error_code: 200 +--- no_error_log +[error] +[crit] +[alert] + +