-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(spec) better rockspec tests
- Loading branch information
1 parent
9f29a06
commit b77dbda
Showing
5 changed files
with
59 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,54 @@ | ||
local stringy = require "stringy" | ||
local IO = require "kong.tools.io" | ||
local fs = require "luarocks.fs" | ||
local pl_dir = require "pl.dir" | ||
local meta = require "kong.meta" | ||
|
||
describe("Rockspec", function() | ||
local rockspec_path, files | ||
describe("rockspec", function() | ||
local rock, lua_srcs = {} | ||
local rock_filename | ||
|
||
setup(function() | ||
for _, filename in ipairs(fs.list_dir(".")) do | ||
if stringy.endswith(filename, "rockspec") then | ||
rockspec_path = filename | ||
break | ||
end | ||
end | ||
if not rockspec_path then | ||
error("can't find rockspec") | ||
end | ||
|
||
loadfile(rockspec_path)() | ||
|
||
local res = IO.os_execute("find . -type f -name *.lua", true) | ||
if not res or stringy.strip(res) == "" then | ||
error("Error executing the command") | ||
end | ||
lua_srcs = pl_dir.getallfiles("./kong", "*.lua") | ||
assert.True(#lua_srcs > 0) | ||
local res = pl_dir.getfiles(".", "kong-*.rockspec") | ||
assert.equal(1, #res) | ||
rock_filename = res[1] | ||
local f = assert(loadfile(res[1])) | ||
setfenv(f, rock) | ||
f() | ||
end) | ||
|
||
files = stringy.split(res, "\n") | ||
it("has same version as meta", function() | ||
assert.matches(meta._VERSION, rock.version:match("(%d.%d.%d)")) | ||
end) | ||
it("has same name as meta", function() | ||
assert.equal(meta._NAME, rock.package) | ||
end) | ||
it("has correct version in filename", function() | ||
local pattern = meta._VERSION:gsub("%.", "%%."):gsub("-", "%%-") | ||
assert.matches(pattern, rock_filename) | ||
end) | ||
|
||
describe("modules", function() | ||
for _, v in ipairs(files) do | ||
it("should include "..v, function() | ||
local path = stringy.strip(v) | ||
if path ~= "" and stringy.startswith(path, "./kong") then | ||
path = string.sub(path, 3) | ||
|
||
local found = false | ||
for mod_name, mod_path in pairs(build.modules) do | ||
if mod_path == path then | ||
found = true | ||
break | ||
end | ||
it("are all included", function() | ||
for _, src in ipairs(lua_srcs) do | ||
src = src:sub(3) -- strip './' | ||
local found | ||
for mod_name, mod_path in pairs(rock.build.modules) do | ||
if mod_path == src then | ||
found = true | ||
break | ||
end | ||
|
||
assert.True(found) | ||
end | ||
end) | ||
end | ||
|
||
for mod_name, mod_path in pairs(build.modules) do | ||
if mod_name ~= "kong" and mod_name ~= "resty_http" and | ||
mod_name ~= "classic" and mod_name ~= "lapp" then | ||
it(mod_path.." has correct name", function() | ||
mod_path = mod_path:gsub("%.lua", ""):gsub("/", '.') | ||
assert.equal(mod_name, mod_path) | ||
end) | ||
assert(found, "could not find module entry for Lua file: "..src) | ||
end | ||
end) | ||
it("all modules named as their path", function() | ||
for mod_name, mod_path in pairs(rock.build.modules) do | ||
if mod_name ~= "kong" and mod_name ~= "resty_http" and | ||
mod_name ~= "classic" and mod_name ~= "lapp" then | ||
mod_path = mod_path:gsub("%.lua", ""):gsub("/", '.') | ||
assert(mod_name == mod_path, mod_path.." has different name ("..mod_name..")") | ||
end | ||
end | ||
end | ||
end) | ||
end) | ||
end) |
This file was deleted.
Oops, something went wrong.