mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-15 17:31:45 +08:00
10e63c637e
* optimize: returns a fetch function when creating a new `lrucache` object, which can be used directly to get cached data. * test: added test case for `core.lrucache` library.
75 lines
1.6 KiB
Perl
75 lines
1.6 KiB
Perl
use t::APISix 'no_plan';
|
|
|
|
repeat_each(2);
|
|
no_long_string();
|
|
no_root_location();
|
|
|
|
run_tests;
|
|
|
|
__DATA__
|
|
|
|
=== TEST 1: sanity
|
|
--- config
|
|
location /t {
|
|
content_by_lua_block {
|
|
local core = require("apisix.core")
|
|
local json_data = core.json.encode({test="test"})
|
|
|
|
ngx.say("encode: ", json_data)
|
|
|
|
local data = core.json.decode(json_data)
|
|
ngx.say("data: ", data.test)
|
|
}
|
|
}
|
|
--- request
|
|
GET /t
|
|
--- response_body
|
|
encode: {"test":"test"}
|
|
data: test
|
|
--- no_error_log
|
|
[error]
|
|
|
|
|
|
|
|
=== TEST 2: delay_encode
|
|
--- config
|
|
location /t {
|
|
content_by_lua_block {
|
|
local core = require("apisix.core")
|
|
local data1 = core.json.delay_encode({test="test1"})
|
|
local data2 = core.json.delay_encode({test="test2"})
|
|
|
|
ngx.say("delay encode: ", data1 == data2)
|
|
ngx.say("data1 type: ", type(data1))
|
|
ngx.log(ngx.ERR, "data1 val: ", data1)
|
|
ngx.log(ngx.ERR, "data2 val: ", data2)
|
|
}
|
|
}
|
|
--- request
|
|
GET /t
|
|
--- response_body
|
|
delay encode: true
|
|
data1 type: table
|
|
--- error_log
|
|
data1 val: {"test":"test2"}
|
|
data2 val: {"test":"test2"}
|
|
|
|
|
|
|
|
=== TEST 3: encode with force argument
|
|
--- config
|
|
location /t {
|
|
content_by_lua_block {
|
|
local core = require("apisix.core")
|
|
local data = core.json.encode({test="test", fun = function() end}, true)
|
|
|
|
ngx.say("encode: ", data)
|
|
}
|
|
}
|
|
--- request
|
|
GET /t
|
|
--- response_body_like eval
|
|
qr/\{"test":"test","fun":"function: 0x[0-9a-f]+"}/
|
|
--- no_error_log
|
|
[error]
|