Skip to content

Commit

Permalink
chore: spec linting + travis-ci linting check
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed May 18, 2015
1 parent c82f305 commit bd9cc83
Showing 24 changed files with 99 additions and 101 deletions.
4 changes: 4 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -5,3 +5,7 @@ globals = {"ngx", "dao", "app", "configuration"}
files["kong/vendor/lapp.lua"] = {
ignore = {"lapp", "typespec"}
}

files["spec/"] = {
globals = {"describe", "it", "before_each", "setup", "after_each", "teardown", "stub", "mock", "spy", "finally"}
}
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ install:
- sudo make install
- sudo make dev

script: "busted --coverage spec/"
script:
- "busted --coverage spec/"
- "luacheck ."

after_success: "luacov-coveralls -i kong"
after_success: "luacov-coveralls -i kong"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ drop:
@bin/kong db -c $(DEVELOPMENT_CONF) drop

lint:
@luacheck kong*.rockspec
@luacheck .

test:
@busted spec/unit
1 change: 0 additions & 1 deletion kong/api/routes/base_controller.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local json = require "cjson"
local utils = require "kong.tools.utils"
local Object = require "classic"
local stringy = require "stringy"
4 changes: 0 additions & 4 deletions spec/integration/admin_api/admin_api_spec.lua
Original file line number Diff line number Diff line change
@@ -174,14 +174,12 @@ describe("Admin API", function()

it("should respond 404 to non existing entities", function()
local response, status = http_client.get(base_url.."/00000000-0000-0000-0000-000000000000")
local body = json.decode(response)
assert.are.equal(404, status)
assert.are.equal('{"message":"Not found"}\n', response)
end)

it("should respond 400 to malformed requests", function()
local response, status = http_client.get(base_url.."/"..CREATED_IDS[endpoint.collection].."blah")
local body = json.decode(response)
assert.are.equal(400, status)
assert.are.equal('{"id":"'..CREATED_IDS[endpoint.collection]..'blah is an invalid uuid"}\n', response)
end)
@@ -201,14 +199,12 @@ describe("Admin API", function()

it("should respond 404 to non existing entities", function()
local response, status = http_client.patch(base_url.."/00000000-0000-0000-0000-000000000000")
local body = json.decode(response)
assert.are.equal(404, status)
assert.are.equal('{"message":"Not found"}\n', response)
end)

it("should respond 400 to malformed requests", function()
local response, status = http_client.patch(base_url.."/"..CREATED_IDS[endpoint.collection].."blah")
local body = json.decode(response)
assert.are.equal(400, status)
assert.are.equal('{"id":"'..CREATED_IDS[endpoint.collection]..'blah is an invalid uuid"}\n', response)
end)
4 changes: 2 additions & 2 deletions spec/integration/cli/start_spec.lua
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ describe("CLI", function()
it("should work when no plugins are enabled and the DB is empty", function()
replace_conf_property("plugins_available", {})

local result, exit_code = spec_helper.start_kong(SERVER_CONF, true)
local _, exit_code = spec_helper.start_kong(SERVER_CONF, true)
assert.are.same(0, exit_code)
end)

@@ -65,7 +65,7 @@ describe("CLI", function()
it("should not fail when an existing plugin is being enabled", function()
replace_conf_property("plugins_available", {"keyauth"})

local result, exit_code = spec_helper.start_kong(SERVER_CONF, true)
local _, exit_code = spec_helper.start_kong(SERVER_CONF, true)
assert.are.same(0, exit_code)
end)

2 changes: 1 addition & 1 deletion spec/integration/cli/version_spec.lua
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ local IO = require "kong.tools.io"
describe("CLI", function()

it("should return the right version", function()
local result, exit_code = IO.os_execute(spec_helper.KONG_BIN.." version")
local result = IO.os_execute(spec_helper.KONG_BIN.." version")
assert.are.same("Kong version: "..constants.VERSION, stringy.strip(result))
end)

17 changes: 7 additions & 10 deletions spec/integration/proxy/database_cache_spec.lua
Original file line number Diff line number Diff line change
@@ -2,9 +2,6 @@ local spec_helper = require "spec.spec_helpers"
local http_client = require "kong.tools.http_client"
local cjson = require "cjson"

local env = spec_helper.get_env()
local created_ids = {}

local kWebURL = spec_helper.API_URL
local kProxyURL = spec_helper.PROXY_URL

@@ -30,44 +27,44 @@ describe("Database cache", function()
local api_id = cjson.decode(response).id
assert.truthy(api_id)

local response, status = http_client.get(kProxyURL.."/get", {}, {host = "cache.test"})
local _, status = http_client.get(kProxyURL.."/get", {}, {host = "cache.test"})
assert.are.equal(200, status)

-- Let's add the authentication plugin configuration
local response, status = http_client.post(kWebURL.."/plugins_configurations/", {
local _, status = http_client.post(kWebURL.."/plugins_configurations/", {
name = "keyauth",
api_id = api_id,
["value.key_names"] = {"x-key"}
})
assert.are.equal(201, status)

-- Making the request immediately after will succeed
local response, status = http_client.get(kProxyURL.."/get", {}, {host = "cache.test"})
local _, status = http_client.get(kProxyURL.."/get", {}, {host = "cache.test"})
assert.are.equal(200, status)

-- But waiting after the cache expiration (5 seconds) should block the request
os.execute("sleep " .. tonumber(5))

local response, status = http_client.get(kProxyURL.."/get", {}, {host = "cache.test"})
local _, status = http_client.get(kProxyURL.."/get", {}, {host = "cache.test"})
assert.are.equal(403, status)

-- Create a consumer and a key will make it work again
local response, status = http_client.post(kWebURL.."/consumers/", {username = "wot"})
assert.are.equal(201, status)
local consumer_id = cjson.decode(response).id

local response, status = http_client.post(kWebURL.."/keyauth_credentials/", {
local _, status = http_client.post(kWebURL.."/keyauth_credentials/", {
consumer_id = consumer_id,
key = "secret_key_123"
})
assert.are.equal(201, status)

-- This should fail, wrong key
local response, status = http_client.get(kProxyURL.."/get", {}, {host = "cache.test", ["x-key"] = "secret_key"})
local _, status = http_client.get(kProxyURL.."/get", {}, {host = "cache.test", ["x-key"] = "secret_key"})
assert.are.equal(403, status)

-- This should work, right key
local response, status = http_client.get(kProxyURL.."/get", {}, {host = "cache.test", ["x-key"] = "secret_key_123"})
local _, status = http_client.get(kProxyURL.."/get", {}, {host = "cache.test", ["x-key"] = "secret_key_123"})
assert.are.equal(200, status)
end)

9 changes: 4 additions & 5 deletions spec/integration/proxy/dns_spec.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local spec_helper = require "spec.spec_helpers"
local http_client = require "kong.tools.http_client"

local STUB_GET_URL = spec_helper.STUB_GET_URL
local TCP_PORT = 7771

describe("DNS", function()
@@ -20,17 +19,17 @@ describe("DNS", function()

it("should work when calling local IP", function()
local thread = spec_helper.start_tcp_server(TCP_PORT) -- Starting the mock TCP server
local response, status = http_client.get(spec_helper.STUB_GET_URL, nil, { host = "dns1.com" })

local _, status = http_client.get(spec_helper.STUB_GET_URL, nil, { host = "dns1.com" })
assert.are.equal(200, status)

thread:join() -- Wait til it exists
end)

it("should work when calling local hostname", function()
local thread = spec_helper.start_tcp_server(TCP_PORT) -- Starting the mock TCP server
local response, status = http_client.get(spec_helper.STUB_GET_URL, nil, { host = "dns2.com" })

local _, status = http_client.get(spec_helper.STUB_GET_URL, nil, { host = "dns2.com" })
assert.are.equal(200, status)

thread:join() -- Wait til it exists
2 changes: 1 addition & 1 deletion spec/integration/proxy/realip_spec.lua
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ describe("Real IP", function()
local uuid,_ = string.gsub(uuid(), "-", "")

-- Making the request
local response, status = http_client.get(STUB_GET_URL, nil,
local _, status = http_client.get(STUB_GET_URL, nil,
{
host = "logging.com",
["X-Forwarded-For"] = "4.4.4.4, 1.1.1.1, 5.5.5.5",
6 changes: 3 additions & 3 deletions spec/integration/proxy/resolver_spec.lua
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ describe("Resolver", function()
describe("Inexistent API", function()

it("should return Not Found when the API is not in Kong", function()
local response, status, headers = http_client.get(spec_helper.STUB_GET_URL, nil, { host = "foo.com" })
local response, status = http_client.get(spec_helper.STUB_GET_URL, nil, { host = "foo.com" })
local body = cjson.decode(response)
assert.are.equal(404, status)
assert.are.equal('API not found with Host: foo.com', body.message)
@@ -34,12 +34,12 @@ describe("Resolver", function()
describe("Existing API", function()

it("should return Success when the API is in Kong", function()
local response, status = http_client.get(STUB_GET_URL, nil, { host = "test4.com"})
local _, status = http_client.get(STUB_GET_URL, nil, { host = "test4.com"})
assert.are.equal(200, status)
end)

it("should return Success when the Host header is not trimmed", function()
local response, status = http_client.get(STUB_GET_URL, nil, { host = " test4.com "})
local _, status = http_client.get(STUB_GET_URL, nil, { host = " test4.com "})
assert.are.equal(200, status)
end)

Loading

0 comments on commit bd9cc83

Please sign in to comment.