kong/t/01-pdk/12-node/03-get_hostname.t (7 lines of code) (raw):
use strict;
use warnings FATAL => 'all';
use Test::Nginx::Socket::Lua;
do "./t/Util.pm";
plan tests => repeat_each() * (blocks() * 3);
run_tests();
__DATA__
=== TEST 1: node.get_id() returns node identifier
--- http_config eval
qq{
$t::Util::HttpConfig
lua_shared_dict kong 24k;
}
--- config
location = /t {
content_by_lua_block {
local PDK = require "kong.pdk"
local pdk = PDK.new()
math.randomseed(ngx.time())
ngx.say(pdk.node.get_id())
}
}
--- request
GET /t
--- response_body_like
^([a-zA-Z0-9](?:(?:[a-zA-Z0-9-]*|(?<!-)\.(?![-.]))*[a-zA-Z0-9]+)?)$
--- no_error_log
[error]