Fix unit tests

Fix sanity unit tests, and do a lot more random testing
This commit is contained in:
Robin Malley 2021-02-03 04:30:27 +00:00
parent 879e89fa8d
commit ec00fcaf08
1 changed files with 28 additions and 13 deletions

View File

@ -27,10 +27,10 @@ local function maybe(input,chance)
return input return input
end end
end end
local rng_any = generate_str(10,characters(".")) local rng_any = generate_str(1024,characters("."))
local rng_subdomain = generate_str(30,characters("[0-9a-z]")) local rng_subdomain = generate_str(30,characters("[0-9a-z]"))
local rng_storyname = generate_str(10,"[a-zA-Z0-9$+!*'(),-]") local rng_storyname = generate_str(10,"[a-zA-Z0-9$+!*'(),-]")
local rng_storyid = function() return tostring(math.random(0,10)) end local rng_storyid = function() return tostring(math.random(1,10)) end
local rng_tags = function() local rng_tags = function()
local tag_gen = generate_str(10,"[%w%d ]") local tag_gen = generate_str(10,"[%w%d ]")
local t = {} local t = {}
@ -188,6 +188,7 @@ local smr_mock_env = {
http_request_cookie = spy.new(function(req,cookie_name) http_request_cookie = spy.new(function(req,cookie_name)
end), end),
http_response_cookie = spy.new(function(req,name,value) req.cookies = {[name] = value} end),
log = spy.new(function(priority, message) end), log = spy.new(function(priority, message) end),
sha3 = spy.new(function(message) return "digest" end), sha3 = spy.new(function(message) return "digest" end),
} }
@ -212,7 +213,20 @@ local smr_override_env = {
string = string_fmt_override string = string_fmt_override
} }
local smr_mock_env_m = { local smr_mock_env_m = {
__index = smr_mock_env __index = smr_mock_env,
__newindex = function(self,key,value)
local setter = debug.getinfo(2)
if setter.source ~= "=[C]" and key ~= "configure" then
error(string.format(
"Tried to create a global %q with value %s\n%s",
key,
tostring(value),
debug.traceback()
),2)
else
rawset(self,key,value)
end
end
} }
describe("smr",function() describe("smr",function()
@ -250,18 +264,19 @@ describe("smr",function()
assert(type(pagefunc) == "function") assert(type(pagefunc) == "function")
end) end)
it("should call http_response() at some point",function() it("should call http_response() at some point",function()
function http_request_get_host(...) end
local pagefunc = require("endpoints." .. fname) local pagefunc = require("endpoints." .. fname)
local req = {} for i = 1,1000 do
req.method = method local req = {}
req.path = obj.route req.method = method
req.args = {} req.path = obj.route
for param_name,param_rng_func in pairs(parameters) do req.args = {}
local param = param_rng_func() for param_name,param_rng_func in pairs(parameters) do
req.args[param_name] = param local param = param_rng_func()
req.args[param_name] = param
end
pagefunc(req)
assert.spy(smr_mock_env.http_response).was_called()
end end
pagefunc(req)
assert.spy(smr_mock_env.http_response).was_called()
end) end)
end) end)