Skip to content

Commit

Permalink
fix(tests) prevent 'kill_all()' from killing resty
Browse files Browse the repository at this point in the history
'pkill nginx' would kill itself since bustde runs in the resty
interpreter. This would only happen on Linux platforms.
  • Loading branch information
thibaultcha committed Jul 19, 2016
1 parent ec1e70d commit f1c4d3e
Show file tree
Hide file tree
Showing 65 changed files with 230 additions and 361 deletions.
4 changes: 2 additions & 2 deletions .ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ set -e

export BUSTED_ARGS="-o gtest -v --exclude-tags=ci"

if [ "$TEST_SUITE" == "unit" ]; then
if [ "$TEST_SUITE" == "lint" ]; then
make lint
elif [ "$TEST_SUITE" == "unit" ]; then
make test
else
createuser --createdb kong
Expand All @@ -17,4 +18,3 @@ else
make test-plugins
fi
fi

2 changes: 1 addition & 1 deletion .ci/setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ eval `luarocks path`
# -------------------------------------
# Install ccm & setup Cassandra cluster
# -------------------------------------
if [ "$TEST_SUITE" != "unit" ]; then
if [ "$TEST_SUITE" != "unit" && "$TEST_SUITE" != "lint" ]; then
pip install --user PyYAML six
git clone https://github.com/pcmanus/ccm.git
pushd ccm
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ addons:
postgresql: "9.4"
apt:
packages:
- sed
- dnsmasq
- uuid-dev
- net-tools
Expand All @@ -23,6 +22,7 @@ env:
- OPENRESTY=1.9.7.3
- $CACHE_DIR=$HOME/cache
matrix:
- TEST_SUITE=lint
- TEST_SUITE=unit
- TEST_SUITE=integration
- TEST_SUITE=plugins
Expand All @@ -42,4 +42,3 @@ cache:
directories:
- $CACHE_DIR
- $HOME/.ccm/repository

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEV_ROCKS = busted luacheck
BUSTED_ARGS ?= -v
TEST_CMD = busted $(BUSTED_ARGS)
TEST_CMD = bin/busted $(BUSTED_ARGS)

.PHONY: install dev lint test test-integration test-plugins test-all

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
local helpers = require "spec.helpers"
local cjson = require "cjson"

describe("helpers: assertions and modifiers;", function()
describe("helpers: assertions and modifiers", function()
local client

setup(function()
helpers.kill_all()

assert(helpers.dao:run_migrations())
assert(helpers.dao.apis:insert {
name = "test-1",
request_host = "mockbin.com",
upstream_url = "http://mockbin.com"
})
assert(helpers.dao.apis:insert {
name = "test-2",
request_host = "httpbin.org",
upstream_url = "http://httpbin.org"
})

helpers.prepare_prefix()
assert(helpers.start_kong())
end)
teardown(function()
helpers.stop_kong()
assert(helpers.stop_kong())
end)

before_each(function()
client = assert(helpers.proxy_client())
client = helpers.proxy_client()
end)
after_each(function()
if client then client:close() end
Expand All @@ -42,7 +40,7 @@ describe("helpers: assertions and modifiers;", function()
method = "GET",
path = "/request",
headers = {
host = "mockbin.com",
host = "mockbin.com"
}
})
assert.response(r).True(true)
Expand All @@ -52,7 +50,7 @@ describe("helpers: assertions and modifiers;", function()
method = "GET",
path = "/request",
headers = {
host = "httpbin.org",
host = "httpbin.org"
}
})
assert.response(r).True(true)
Expand All @@ -70,7 +68,7 @@ describe("helpers: assertions and modifiers;", function()
method = "GET",
path = "/request",
headers = {
host = "mockbin.com",
host = "mockbin.com"
}
})
assert.request(r).True(true)
Expand All @@ -81,7 +79,7 @@ describe("helpers: assertions and modifiers;", function()
method = "GET",
path = "/get",
headers = {
host = "httpbin.org",
host = "httpbin.org"
}
})
assert.request(r).True(true)
Expand All @@ -95,7 +93,7 @@ describe("helpers: assertions and modifiers;", function()
},
headers = {
host = "httpbin.org",
["Content-Type"] = "www-form-urlencoded",
["Content-Type"] = "www-form-urlencoded"
}
})
assert.request(r).True(true)
Expand All @@ -105,7 +103,7 @@ describe("helpers: assertions and modifiers;", function()
method = "GET",
path = "/headers", -- this path is not supported, but should yield valid json for the test
headers = {
host = "httpbin.org",
host = "httpbin.org"
}
})
assert.error(function() assert.request(r).True(true) end)
Expand All @@ -127,7 +125,7 @@ describe("helpers: assertions and modifiers;", function()
method = "GET",
path = "/get",
headers = {
host = "httpbin.org",
host = "httpbin.org"
}
})
assert.status(200, r)
Expand All @@ -138,7 +136,7 @@ describe("helpers: assertions and modifiers;", function()
method = "GET",
path = "/status/404",
headers = {
host = "httpbin.org",
host = "httpbin.org"
}
})
assert.response(r).has.status(404)
Expand All @@ -159,7 +157,7 @@ describe("helpers: assertions and modifiers;", function()
method = "GET",
path = "/request",
headers = {
host = "mockbin.com",
host = "mockbin.com"
}
})
local json = assert.response(r).has.jsonbody()
Expand All @@ -172,7 +170,7 @@ describe("helpers: assertions and modifiers;", function()
body = { hello = "world" },
headers = {
host = "mockbin.com",
["Content-Type"] = "application/json",
["Content-Type"] = "application/json"
}
})
local json = assert.request(r).has.jsonbody()
Expand All @@ -185,7 +183,7 @@ describe("helpers: assertions and modifiers;", function()
body = { hello = "world" },
headers = {
host = "httpbin.org",
["Content-Type"] = "application/json",
["Content-Type"] = "application/json"
}
})
assert.error(function() assert.request(r).has.jsonbody() end)
Expand All @@ -200,7 +198,7 @@ describe("helpers: assertions and modifiers;", function()
body = { hello = "world" },
headers = {
host = "mockbin.com",
["Content-Type"] = "application/json",
["Content-Type"] = "application/json"
}
})
local v1 = assert.response(r).has.header("x-powered-by")
Expand All @@ -214,7 +212,7 @@ describe("helpers: assertions and modifiers;", function()
path = "/request",
headers = {
host = "mockbin.com",
["just-a-test-header"] = "just-a-test-value",
["just-a-test-header"] = "just-a-test-value"
}
})
local v1 = assert.request(r).has.header("just-a-test-header")
Expand All @@ -229,7 +227,7 @@ describe("helpers: assertions and modifiers;", function()
path = "/get",
headers = {
host = "httpbin.org",
["just-a-test-header"] = "just-a-test-value",
["just-a-test-header"] = "just-a-test-value"
}
})
local v1 = assert.request(r).has.header("just-a-test-header")
Expand All @@ -249,7 +247,7 @@ describe("helpers: assertions and modifiers;", function()
hello = "world"
},
headers = {
host = "mockbin.com",
host = "mockbin.com"
}
})
local v1 = assert.request(r).has.queryparam("hello")
Expand All @@ -270,7 +268,7 @@ describe("helpers: assertions and modifiers;", function()
},
headers = {
host = "httpbin.org",
["Content-Type"] = "application/json",
["Content-Type"] = "application/json"
}
})
local v1 = assert.request(r).has.queryparam("hello")
Expand All @@ -291,7 +289,7 @@ describe("helpers: assertions and modifiers;", function()
},
headers = {
host = "mockbin.com",
["Content-Type"] = "application/x-www-form-urlencoded",
["Content-Type"] = "application/x-www-form-urlencoded"
}
})
local v1 = assert.request(r).has.formparam("hello")
Expand All @@ -309,7 +307,7 @@ describe("helpers: assertions and modifiers;", function()
},
headers = {
host = "mockbin.com",
["Content-Type"] = "application/json",
["Content-Type"] = "application/json"
}
})
assert.error(function() assert.request(r).has.formparam("hello") end)
Expand All @@ -323,7 +321,7 @@ describe("helpers: assertions and modifiers;", function()
},
headers = {
host = "httpbin.org",
["Content-Type"] = "application/x-www-form-urlencoded",
["Content-Type"] = "application/x-www-form-urlencoded"
}
})
local v1 = assert.request(r).has.formparam("hello")
Expand All @@ -341,11 +339,10 @@ describe("helpers: assertions and modifiers;", function()
},
headers = {
host = "httpbin.org",
["Content-Type"] = "application/json",
["Content-Type"] = "application/json"
}
})
assert.error(function() assert.request(r).has.formparam("hello") end)
end)
end)

end)
Loading

0 comments on commit f1c4d3e

Please sign in to comment.