Skip to content

Commit

Permalink
tests: switch from httpbin to mockbin + make clean
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Mar 10, 2015
1 parent 664dee6 commit c3d1e61
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 121 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
KONG_HOME = `pwd`
DEVELOPMENT_CONF ?= kong_DEVELOPMENT.yml
TESTING_CONF = kong_TEST.yml
DEVELOPMENT_CONF = kong_DEVELOPMENT.yml

.PHONY: install dev seed drop test coverage test-api test-proxy test-server test-all
.PHONY: install dev clean seed drop test coverage test-api test-proxy test-server test-all

install:
@if [ `uname` == "Darwin" ]; then \
Expand All @@ -18,6 +19,12 @@ dev:
@scripts/config.lua -k $(KONG_HOME) -e DEVELOPMENT create
@scripts/db.lua -c $(DEVELOPMENT_CONF) migrate

clean:
@rm -f luacov.*
@scripts/db.lua -c $(DEVELOPMENT_CONF) reset
@rm -f $(DEVELOPMENT_CONF) $(TESTING_CONF)
@rm -rf nginx_tmp

run:
@bin/kong -c $(DEVELOPMENT_CONF) start

Expand Down
16 changes: 8 additions & 8 deletions spec/integration/api/api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ local kWebURL = spec_helper.API_URL
local ENDPOINTS = {
{
collection = "apis",
total = 7,
total = table.getn(spec_helper.faker.FIXTURES.api) + 1,
entity = {
public_dns = "api.httpbin.com",
name = "httpbin",
target_url = "http://httpbin.org"
public_dns = "api.mockbin.com",
name = "mockbin",
target_url = "http://mockbin.com"
},
update_fields = {
public_dns = "newapi.httpbin.com"
public_dns = "newapi.mockbin.com"
},
error_message = '{"public_dns":"public_dns is required","name":"name is required","target_url":"target_url is required"}'
},
{
collection = "accounts",
total = 3,
total = table.getn(spec_helper.faker.FIXTURES.account) + 1,
entity = {
provider_id = "123456789"
},
Expand All @@ -32,7 +32,7 @@ local ENDPOINTS = {
},
{
collection = "applications",
total = 4,
total = table.getn(spec_helper.faker.FIXTURES.application) + 1,
entity = {
public_key = "PUB_key",
secret_key = "SEC_key",
Expand All @@ -48,7 +48,7 @@ local ENDPOINTS = {
},
{
collection = "plugins",
total = 8,
total = table.getn(spec_helper.faker.FIXTURES.plugin) + 1,
entity = {
name = "ratelimiting",
api_id = function()
Expand Down
191 changes: 96 additions & 95 deletions spec/unit/utils_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("Utils #tools", function()
describe("Cache", function()

it("should return a valid API cache key", function()
assert.are.equal("apis/httpbin.org", utils.cache_api_key("httpbin.org"))
assert.are.equal("apis/mockbin.com", utils.cache_api_key("mockbin.com"))
end)

it("should return a valid PLUGIN cache key", function()
Expand All @@ -20,149 +20,150 @@ describe("Utils #tools", function()

end)

describe("#sort_table_iter()", function()

it("should sort a table in ascending order by its keys without order set", function()
local t = {
[1] = "one",
[3] = "three",
[2] = "two"
}

local keyset = {}
for k,v in utils.sort_table_iter(t) do
table.insert(keyset, k)
end

assert.are.same({1, 2, 3}, keyset)
end)

it("should sort a table in ascending order by its keys with ascending order set", function()
local t = {
[1] = "one",
[3] = "three",
[2] = "two"
}

local keyset = {}
for k,v in utils.sort_table_iter(t, utils.sort.ascending) do
table.insert(keyset, k)
end

assert.are.same({1, 2, 3}, keyset)
end)

it("should sort a table in descending order by its keys with descending order set", function()
local t = {
[1] = "one",
[3] = "three",
[2] = "two"
}

local keyset = {}
for k,v in utils.sort_table_iter(t, utils.sort.descending) do
table.insert(keyset, k)
end

assert.are.same({3, 2, 1}, keyset)
end)

it("should sort an array in ascending order by its keys without order set", function()
local t = { 3, 1, 2 }

local keyset = {}
for k,v in utils.sort_table_iter(t) do
table.insert(keyset, k)
end

assert.are.same({1, 2, 3}, keyset)
end)

it("should sort an array in ascending order by its keys with ascending order set", function()
local t = { 3, 1, 2 }

local keyset = {}
for k,v in utils.sort_table_iter(t, utils.sort.ascending) do
table.insert(keyset, k)
end

assert.are.same({1, 2, 3}, keyset)
end)

it("should sort an array in descending order by its keys with descending order set", function()
local t = { 3, 1, 2 }

local keyset = {}
for k,v in utils.sort_table_iter(t, utils.sort.descending) do
table.insert(keyset, k)
end

assert.are.same({3, 2, 1}, keyset)
end)

end)

describe("HTTP", function()

describe("GET", function()

it("should return a valid GET response", function()
local response, status, headers = utils.get("http://httpbin.org/get", {name = "Mark"}, {Custom = "pippo"})
local response, status, headers = utils.get("http://mockbin.com/request", {name = "Mark"}, {Custom = "pippo"})
assert.are.equal(200, status)
assert.truthy(headers)
assert.truthy(response)
local parsed_response = cjson.decode(response)
assert.are.equal("Mark", parsed_response.args.name)
assert.are.equal("pippo", parsed_response.headers.Custom)
assert.are.equal("Mark", parsed_response.queryString.name)
assert.are.equal("pippo", parsed_response.headers.custom)
end)

end)

describe("POST", function()

it("should return a valid POST response", function()
local response, status, headers = utils.post("http://httpbin.org/post", {name = "Mark"}, {Custom = "pippo"})
local response, status, headers = utils.post("http://mockbin.com/request", {name = "Mark"}, {Custom = "pippo"})
assert.are.equal(200, status)
assert.truthy(headers)
assert.truthy(response)
local parsed_response = cjson.decode(response)
assert.are.equal("Mark", parsed_response.form.name)
assert.are.equal("pippo", parsed_response.headers.Custom)
assert.are.equal("Mark", parsed_response.postData.params.name)
assert.are.equal("pippo", parsed_response.headers.custom)
end)

end)

describe("PUT", function()

it("should return a valid PUT response", function()
local response, status, headers = utils.put("http://httpbin.org/put", {name="Mark"}, {Custom = "pippo"})
local response, status, headers = utils.put("http://mockbin.com/request", {name="Mark"}, {Custom = "pippo"})
assert.are.equal(200, status)
assert.truthy(headers)
assert.truthy(response)
local parsed_response = cjson.decode(response)
assert.are.equal("Mark", parsed_response.json.name)
assert.are.equal("pippo", parsed_response.headers.Custom)
local json_params = cjson.decode(parsed_response.postData.text)
assert.are.equal("Mark", json_params.name)
assert.are.equal("pippo", parsed_response.headers.custom)
end)

end)

describe("DELETE", function()

it("should return a valid DELETE response", function()
local response, status, headers = utils.delete("http://httpbin.org/delete", {name = "Mark"}, {Custom = "pippo"})
local response, status, headers = utils.delete("http://mockbin.com/request", {name = "Mark"}, {Custom = "pippo"})
assert.are.equal(200, status)
assert.truthy(headers)
assert.truthy(response)
local parsed_response = cjson.decode(response)
assert.are.equal("Mark", parsed_response.args.name)
assert.are.equal("pippo", parsed_response.headers.Custom)
assert.are.equal("Mark", parsed_response.queryString.name)
assert.are.equal("pippo", parsed_response.headers.custom)
end)

end)
end)

describe("tables", function()

describe("#sort_table_iter()", function()

it("should sort a table in ascending order by its keys without order set", function()
local t = {
[1] = "one",
[3] = "three",
[2] = "two"
}

local keyset = {}
for k,v in utils.sort_table_iter(t) do
table.insert(keyset, k)
end

assert.are.same({1, 2, 3}, keyset)
end)

it("should sort a table in ascending order by its keys with ascending order set", function()
local t = {
[1] = "one",
[3] = "three",
[2] = "two"
}

local keyset = {}
for k,v in utils.sort_table_iter(t, utils.sort.ascending) do
table.insert(keyset, k)
end

assert.are.same({1, 2, 3}, keyset)
end)

it("should sort a table in descending order by its keys with descending order set", function()
local t = {
[1] = "one",
[3] = "three",
[2] = "two"
}

local keyset = {}
for k,v in utils.sort_table_iter(t, utils.sort.descending) do
table.insert(keyset, k)
end

assert.are.same({3, 2, 1}, keyset)
end)

it("should sort an array in ascending order by its keys without order set", function()
local t = { 3, 1, 2 }

local keyset = {}
for k,v in utils.sort_table_iter(t) do
table.insert(keyset, k)
end

assert.are.same({1, 2, 3}, keyset)
end)

it("should sort an array in ascending order by its keys with ascending order set", function()
local t = { 3, 1, 2 }

local keyset = {}
for k,v in utils.sort_table_iter(t, utils.sort.ascending) do
table.insert(keyset, k)
end

assert.are.same({1, 2, 3}, keyset)
end)

it("should sort an array in descending order by its keys with descending order set", function()
local t = { 3, 1, 2 }

local keyset = {}
for k,v in utils.sort_table_iter(t, utils.sort.descending) do
table.insert(keyset, k)
end

assert.are.same({3, 2, 1}, keyset)
end)

end)

describe("#is_empty()", function()

it("should return true for empty table, false otherwise", function()
Expand Down
Loading

0 comments on commit c3d1e61

Please sign in to comment.