Skip to content

Commit

Permalink
chore(ci) parallelize travis tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Jan 12, 2016
1 parent 65130bb commit 53830c6
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 50 deletions.
15 changes: 15 additions & 0 deletions .ci/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

CMD="busted -v -o gtest --exclude-tags=ci"

if [ "$TEST_SUITE" == "unit" ]; then
CMD="$CMD --coverage spec/unit && luacov-coveralls -i kong"
elif [ "$TEST_SUITE" == "plugins" ]; then
CMD="$CMD spec/plugins"
elif [ "$TEST_SUITE" == "integration" ]; then
CMD="$CMD spec/integration"
fi

eval $CMD
5 changes: 5 additions & 0 deletions .ci/setup_cassandra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -e

if [ "$TEST_SUITE" == "unit" ]; then
echo "Exiting, no integration tests"
exit
fi

arr=(${CASSANDRA_HOSTS//,/ })

pip install --user PyYAML six
Expand Down
4 changes: 2 additions & 2 deletions .ci/setup_lua.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ if [ "$LUAJIT" == "yes" ]; then

# If cache is empty, download and compile
if [ ! "$(ls -A $LUAJIT_DIR)" ]; then
git clone https://github.com/luajit/luajit
pushd luajit
git clone https://github.com/luajit/luajit $LUAJIT_DIR
pushd $LUAJIT_DIR

if [ "$LUA" == "luajit-2.0" ]; then
git checkout v2.0.4
Expand Down
5 changes: 5 additions & 0 deletions .ci/setup_openresty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -e

if [ "$TEST_SUITE" == "unit" ]; then
echo "Exiting, no integration tests"
exit
fi

mkdir -p $OPENRESTY_DIR

if [ ! "$(ls -A $OPENRESTY_DIR)" ]; then
Expand Down
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ env:
- LUAROCKS_DIR=$HOME/luarocks
- OPENRESTY_DIR=$HOME/openresty
- CASSANDRA_HOSTS=127.0.0.1
matrix:
- TEST_SUITE=unit
- TEST_SUITE=integration
- TEST_SUITE=plugins
before_install:
- bash .ci/setup_lua.sh
- bash .ci/setup_openresty.sh
Expand All @@ -37,9 +41,7 @@ install:
- 'sed -i "2 i\dns_resolver: server" kong_TEST.yml'
script:
- make lint
- "busted --exclude-tags=ci -o spec/busted-print.lua --coverage spec/"
after_success:
- "luacov-coveralls -i kong"
- .ci/run_tests.sh
cache:
apt: true
pip: true
Expand Down
20 changes: 0 additions & 20 deletions spec/busted-print.lua

This file was deleted.

1 change: 1 addition & 0 deletions spec/plugins/basic-auth/api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("Basic Auth Credentials API", function()
describe("POST", function()

teardown(function()
if credential == nil then return end -- teardown gets executed even if the tag was excluded
local dao = spec_helper.get_env().dao_factory
local ok, err = dao.basicauth_credentials:delete(credential)
assert.True(ok)
Expand Down
5 changes: 3 additions & 2 deletions spec/plugins/hmac-auth/api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("HMAC Auth Credentials API", function()
consumer = fixtures.consumer[1]
BASE_URL = spec_helper.API_URL.."/consumers/bob/hmac-auth/"
end)

describe("POST", function()

it("[SUCCESS] should create a hmac-auth credential", function()
Expand All @@ -43,6 +43,7 @@ describe("HMAC Auth Credentials API", function()

describe("PUT", function()
setup(function()
if credential == nil then return end
spec_helper.get_env().dao_factory.hmacauth_credentials:delete({id = credential.id})
end)

Expand Down Expand Up @@ -104,7 +105,7 @@ describe("HMAC Auth Credentials API", function()
end)

describe("DELETE", function()

it("[FAILURE] should return proper errors", function()
local _, status = http_client.delete(BASE_URL.."blah")
assert.equal(400, status)
Expand Down
1 change: 1 addition & 0 deletions spec/plugins/jwt/api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("JWT API", function()
local jwt1, jwt2

teardown(function()
if jwt1 == nil then return end
jwt_secrets:delete(jwt1)
jwt_secrets:delete(jwt2)
end)
Expand Down
2 changes: 1 addition & 1 deletion spec/plugins/key-auth/access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local cjson = require "cjson"
local STUB_GET_URL = spec_helper.STUB_GET_URL
local STUB_POST_URL = spec_helper.STUB_POST_URL

describe("Authentication Plugin", function()
describe("key-auth plugin", function()

setup(function()
spec_helper.prepare_db()
Expand Down
2 changes: 1 addition & 1 deletion spec/plugins/key-auth/api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local json = require "cjson"
local http_client = require "kong.tools.http_client"
local spec_helper = require "spec.spec_helpers"

describe("Key Auth Credentials API", function()
describe("key-auth credentials API", function()
local BASE_URL, credential, consumer

setup(function()
Expand Down
2 changes: 1 addition & 1 deletion spec/plugins/key-auth/daos_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local env = spec_helper.get_env()
local dao_factory = env.dao_factory
local faker = env.faker

describe("DAO key-auth Credentials", function()
describe("key-auth credentials DAO", function()

setup(function()
spec_helper.prepare_db()
Expand Down
20 changes: 5 additions & 15 deletions spec/plugins/oauth2/schema_spec.lua
Original file line number Diff line number Diff line change
@@ -1,48 +1,38 @@
local validate_entity = require("kong.dao.schemas_validation").validate_entity
local oauth2_schema = require "kong.plugins.oauth2.schema"

require "kong.tools.ngx_stub"

describe("OAuth2 Entities Schemas", function()

describe("OAuth2 Configuration", function()

it("should not require a `scopes` when `mandatory_scope` is false", function()
local valid, errors = validate_entity({ mandatory_scope = false }, oauth2_schema)
local valid, errors = validate_entity({mandatory_scope = false}, oauth2_schema)
assert.truthy(valid)
assert.falsy(errors)
end)

it("should require a `scopes` when `mandatory_scope` is true", function()
local valid, errors = validate_entity({ mandatory_scope = true }, oauth2_schema)
local valid, errors = validate_entity({mandatory_scope = true}, oauth2_schema)
assert.falsy(valid)
assert.equal("To set a mandatory scope you also need to create available scopes", errors.mandatory_scope)
end)

it("should pass when both `scopes` when `mandatory_scope` are passed", function()
local valid, errors = validate_entity({ mandatory_scope = true, scopes = { "email", "info" } }, oauth2_schema)
local valid, errors = validate_entity({mandatory_scope = true, scopes = {"email", "info"}}, oauth2_schema)
assert.truthy(valid)
assert.falsy(errors)
end)

it("should autogenerate a `provision_key` when it is not being passed", function()
local t = { mandatory_scope = true, scopes = { "email", "info" } }
local t = {mandatory_scope = true, scopes = {"email", "info"}}
local valid, errors = validate_entity(t, oauth2_schema)
assert.truthy(valid)
assert.falsy(errors)
assert.truthy(t.provision_key)
assert.are.equal(32, t.provision_key:len())
end)

it("should not autogenerate a `provision_key` when it is being passed", function()
local t = { mandatory_scope = true, scopes = { "email", "info" }, provision_key = "hello" }
local t = {mandatory_scope = true, scopes = {"email", "info"}, provision_key = "hello"}
local valid, errors = validate_entity(t, oauth2_schema)
assert.truthy(valid)
assert.falsy(errors)
assert.truthy(t.provision_key)
assert.are.equal("hello", t.provision_key)
end)

end)

end)
8 changes: 4 additions & 4 deletions spec/plugins/request-transformer/access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe("Request Transformer", function()
teardown(function()
spec_helper.stop_kong()
end)

describe("Test remove", function()
it("should remove specified header", function()
local response, status = http_client.get(STUB_GET_URL, {}, {host = "test4.com", ["x-to-remove"] = "true", ["x-another-header"] = "true"})
Expand Down Expand Up @@ -132,7 +132,7 @@ describe("Request Transformer", function()
assert.equal("v2", body.queryString["q2"])
end)
end)

describe("Test replace", function()
it("should replace specified header if it exist", function()
local response, status = http_client.get(STUB_GET_URL, {}, {host = "test5.com", ["h1"] = "V", ["h2"] = "v2"})
Expand Down Expand Up @@ -191,7 +191,7 @@ describe("Request Transformer", function()
assert.equal("v2", body.queryString["q2"])
end)
end)

describe("Test add", function()
it("should add new headers", function()
local response, status = http_client.get(STUB_GET_URL, {}, {host = "test1.com"})
Expand Down Expand Up @@ -253,7 +253,7 @@ describe("Request Transformer", function()
assert.equal("httpbin.org", body.headers["Host"])
end)
end)

describe("Test append ", function()
it("should add a new header if header does not exists", function()
local response, status = http_client.get(STUB_GET_URL, {}, {host = "test6.com"})
Expand Down
2 changes: 1 addition & 1 deletion spec/plugins/ssl/api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local http_client = require "kong.tools.http_client"
local spec_helper = require "spec.spec_helpers"
local ssl_fixtures = require "spec.plugins.ssl.fixtures"

describe("SSL API", function()
describe("SSL Admin API", function()
local BASE_URL

setup(function()
Expand Down

0 comments on commit 53830c6

Please sign in to comment.