Skip to content

Commit

Permalink
refactor(spec) better rockspec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Mar 23, 2016
1 parent 9f29a06 commit b77dbda
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 100 deletions.
32 changes: 12 additions & 20 deletions kong-0.7.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ description = {
dependencies = {
"luasec ~> 0.5-2",

"penlight ~> 1.3.2",
"lua_uuid ~> 0.2.0-2",
"lua_system_constants ~> 0.1.1-0",
"luatz ~> 0.3-1",
Expand Down Expand Up @@ -44,6 +45,7 @@ build = {
["lapp"] = "kong/vendor/lapp.lua",
["resty_http"] = "kong/vendor/resty_http.lua",

["kong.meta"] = "kong/meta.lua",
["kong.constants"] = "kong/constants.lua",
["kong.singletons"] = "kong/singletons.lua",

Expand All @@ -66,6 +68,16 @@ build = {
["kong.cli.services.serf"] = "kong/cli/services/serf.lua",
["kong.cli.services.nginx"] = "kong/cli/services/nginx.lua",

["kong.api.app"] = "kong/api/app.lua",
["kong.api.crud_helpers"] = "kong/api/crud_helpers.lua",
["kong.api.route_helpers"] = "kong/api/route_helpers.lua",
["kong.api.routes.kong"] = "kong/api/routes/kong.lua",
["kong.api.routes.apis"] = "kong/api/routes/apis.lua",
["kong.api.routes.consumers"] = "kong/api/routes/consumers.lua",
["kong.api.routes.plugins"] = "kong/api/routes/plugins.lua",
["kong.api.routes.cache"] = "kong/api/routes/cache.lua",
["kong.api.routes.cluster"] = "kong/api/routes/cluster.lua",

["kong.tools.io"] = "kong/tools/io.lua",
["kong.tools.utils"] = "kong/tools/utils.lua",
["kong.tools.faker"] = "kong/tools/faker.lua",
Expand Down Expand Up @@ -106,15 +118,6 @@ build = {
["kong.dao.migrations.cassandra"] = "kong/dao/migrations/cassandra.lua",
["kong.dao.migrations.postgres"] = "kong/dao/migrations/postgres.lua",

["kong.api.app"] = "kong/api/app.lua",
["kong.api.crud_helpers"] = "kong/api/crud_helpers.lua",
["kong.api.route_helpers"] = "kong/api/route_helpers.lua",
["kong.api.routes.kong"] = "kong/api/routes/kong.lua",
["kong.api.routes.apis"] = "kong/api/routes/apis.lua",
["kong.api.routes.consumers"] = "kong/api/routes/consumers.lua",
["kong.api.routes.plugins"] = "kong/api/routes/plugins.lua",
["kong.api.routes.plugins"] = "kong/api/routes/plugins.lua",

["kong.plugins.base_plugin"] = "kong/plugins/base_plugin.lua",

["kong.plugins.basic-auth.migrations.cassandra"] = "kong/plugins/basic-auth/migrations/cassandra.lua",
Expand Down Expand Up @@ -218,16 +221,6 @@ build = {
["kong.plugins.acl.api"] = "kong/plugins/acl/api.lua",
["kong.plugins.acl.daos"] = "kong/plugins/acl/daos.lua",

["kong.api.app"] = "kong/api/app.lua",
["kong.api.crud_helpers"] = "kong/api/crud_helpers.lua",
["kong.api.route_helpers"] = "kong/api/route_helpers.lua",
["kong.api.routes.kong"] = "kong/api/routes/kong.lua",
["kong.api.routes.apis"] = "kong/api/routes/apis.lua",
["kong.api.routes.consumers"] = "kong/api/routes/consumers.lua",
["kong.api.routes.plugins"] = "kong/api/routes/plugins.lua",
["kong.api.routes.cache"] = "kong/api/routes/cache.lua",
["kong.api.routes.cluster"] = "kong/api/routes/cluster.lua",

["kong.plugins.jwt.migrations.cassandra"] = "kong/plugins/jwt/migrations/cassandra.lua",
["kong.plugins.jwt.migrations.postgres"] = "kong/plugins/jwt/migrations/postgres.lua",
["kong.plugins.jwt.handler"] = "kong/plugins/jwt/handler.lua",
Expand Down Expand Up @@ -255,7 +248,6 @@ build = {
["kong.plugins.datadog.handler"] = "kong/plugins/datadog/handler.lua",
["kong.plugins.datadog.schema"] = "kong/plugins/datadog/schema.lua",
["kong.plugins.datadog.statsd_logger"] = "kong/plugins/datadog/statsd_logger.lua"

},
install = {
conf = { "kong.yml" },
Expand Down
4 changes: 2 additions & 2 deletions kong/kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
local meta = require "kong.meta"

_G._KONG = {
_NAME = meta.name,
_VERSION = tostring(meta.version)
_NAME = meta._NAME,
_VERSION = meta._VERSION
}

local core = require "kong.core.handler"
Expand Down
5 changes: 3 additions & 2 deletions kong/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local version = setmetatable({
})

return {
name = "Kong",
version = version
_NAME = "kong",
_VERSION = tostring(version),
__VERSION = version
}
89 changes: 42 additions & 47 deletions spec/unit/rockspec_spec.lua
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)
29 changes: 0 additions & 29 deletions spec/unit/statics_spec.lua

This file was deleted.

0 comments on commit b77dbda

Please sign in to comment.