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
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_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 tag_gen = generate_str(10,"[%w%d ]")
local t = {}
@ -188,6 +188,7 @@ local smr_mock_env = {
http_request_cookie = spy.new(function(req,cookie_name)
end),
http_response_cookie = spy.new(function(req,name,value) req.cookies = {[name] = value} end),
log = spy.new(function(priority, message) end),
sha3 = spy.new(function(message) return "digest" end),
}
@ -212,7 +213,20 @@ local smr_override_env = {
string = string_fmt_override
}
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()
@ -250,8 +264,8 @@ describe("smr",function()
assert(type(pagefunc) == "function")
end)
it("should call http_response() at some point",function()
function http_request_get_host(...) end
local pagefunc = require("endpoints." .. fname)
for i = 1,1000 do
local req = {}
req.method = method
req.path = obj.route
@ -262,6 +276,7 @@ describe("smr",function()
end
pagefunc(req)
assert.spy(smr_mock_env.http_response).was_called()
end
end)
end)