mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-03 04:27:36 +08:00
test: added test case about core.id
and core.utils
library.
This commit is contained in:
parent
a41d54a653
commit
0ab3e53cb9
@ -1,6 +1,7 @@
|
||||
local log = require("apisix.core.log")
|
||||
local uuid = require('resty.jit-uuid')
|
||||
local smatch = string.match
|
||||
local open = io.open
|
||||
|
||||
|
||||
local prefix = ngx.config.prefix()
|
||||
@ -15,7 +16,7 @@ end
|
||||
|
||||
|
||||
local function read_file(path)
|
||||
local file = io.open(path, "rb") -- r read mode and b binary mode
|
||||
local file = open(path, "rb") -- r read mode and b binary mode
|
||||
if not file then
|
||||
return nil
|
||||
end
|
||||
@ -27,7 +28,7 @@ end
|
||||
|
||||
|
||||
local function write_file(path, data)
|
||||
local file = io.open(path ,"w+")
|
||||
local file = open(path ,"w+")
|
||||
if not file then
|
||||
return nil, "failed to open file[" .. path .. "] for writing"
|
||||
end
|
||||
@ -46,7 +47,7 @@ function _M.init()
|
||||
end
|
||||
|
||||
apisix_uid = uuid.generate_v4()
|
||||
log.warn("not found apisix uid, generate a new one: ", apisix_uid)
|
||||
log.notice("not found apisix uid, generate a new one: ", apisix_uid)
|
||||
|
||||
local ok, err = write_file(uid_file_path, apisix_uid)
|
||||
if not ok then
|
||||
|
@ -1,4 +1,3 @@
|
||||
local log = require("apisix.core.log")
|
||||
local open = io.open
|
||||
|
||||
|
||||
|
26
t/core-id.t
Normal file
26
t/core-id.t
Normal file
@ -0,0 +1,26 @@
|
||||
use t::APISix 'no_plan';
|
||||
|
||||
repeat_each(1);
|
||||
no_long_string();
|
||||
no_root_location();
|
||||
log_level("info");
|
||||
|
||||
run_tests;
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: sanity
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local core = require("apisix.core")
|
||||
|
||||
ngx.say("uid: ", core.id.get())
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body_like eval
|
||||
qr/uid: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
|
||||
--- error_log
|
||||
not found apisix uid, generate a new one
|
25
t/core-utils.t
Normal file
25
t/core-utils.t
Normal file
@ -0,0 +1,25 @@
|
||||
use t::APISix 'no_plan';
|
||||
|
||||
repeat_each(1);
|
||||
no_long_string();
|
||||
no_root_location();
|
||||
log_level("info");
|
||||
|
||||
run_tests;
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: sanity
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local get_seed = require("apisix.core.utils").get_seed_from_urandom
|
||||
|
||||
ngx.say("random seed ", get_seed())
|
||||
ngx.say("twice: ", get_seed() == get_seed())
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body_like eval
|
||||
qr/random seed \d+\ntwice: false/
|
Loading…
Reference in New Issue
Block a user