Skip to content

Instantly share code, notes, and snippets.

@hishamhm
Created December 18, 2019 17:09
Show Gist options
  • Save hishamhm/682da032c648a53124e12aeabb0e0cdd to your computer and use it in GitHub Desktop.
Save hishamhm/682da032c648a53124e12aeabb0e0cdd to your computer and use it in GitHub Desktop.
#!/usr/bin/env resty
setmetatable(_G, nil)
local tests = require("spec.fixtures.router_path_handling_tests")
local tabular = require("tabular")
print(tabular(tests))
local function every(xs, field_name)
local vs = {}
local set = {}
for _, x in ipairs(xs) do
local v = tostring(x[field_name])
if not set[v] then
table.insert(vs, v)
end
set[v] = true
end
table.sort(vs)
return vs
end
local service_paths = every(tests, "service_path")
local route_paths = every(tests, "route_path")
local request_paths = every(tests, "request_path")
local combos = {}
for _, serp in ipairs(service_paths) do
for _, roup in ipairs(route_paths) do
for _, reqp in ipairs(request_paths) do
for _, strp in ipairs({"false", "true"}) do
for _, path in ipairs({"v0", "v1"}) do
combos[table.concat({serp, roup, reqp, strp, path}, " ")] = "unchecked"
end
end
end
end
end
local function checked(serp, roup, reqp, strp, path)
if type(strp) == "table" then
for _, s in ipairs(strp) do
checked(serp, roup, reqp, s, path)
end
elseif type(path) == "table" then
for _, p in ipairs(path) do
checked(serp, roup, reqp, strp, p)
end
else
combos[table.concat({serp, tostring(roup), reqp, tostring(strp), path}, " ")] = "checked"
end
end
for _, t in ipairs(tests) do
checked(t.service_path, t.route_path, t.request_path, t.strip_path, t.path_handling)
end
print(tabular(combos))
local results = {}
for combo, mode in pairs(combos) do
results[mode] = (results[mode] or 0) + 1
end
print(tabular(results))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment