-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing spec_helpers for self-sustainable busted tests
The spec_helper will be able to migrate and reset the db, start and stop Kong, to ideally not depend on the Makefile anymore for those operations.
- Loading branch information
1 parent
3f8244f
commit b036a32
Showing
10 changed files
with
81 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
local utils = require "kong.tools.utils" | ||
local Faker = require "kong.tools.faker" | ||
local Migrations = require "kong.tools.migrations" | ||
|
||
-- Constants | ||
local KONG_BIN = "bin/kong" | ||
local TEST_CONF_FILE = "kong_TEST.yml" | ||
|
||
-- DB objects | ||
local configuration, dao_factory = utils.load_configuration_and_dao(TEST_CONF_FILE) | ||
local migrations = Migrations(dao_factory) | ||
local faker = Faker(dao_factory) | ||
|
||
local _M = {} | ||
|
||
_M.CONF_FILE = TEST_CONF_FILE | ||
_M.configuration = configuration | ||
_M.dao_factory = dao_factory | ||
_M.faker = faker | ||
|
||
function _M.os_execute(command) | ||
local n = os.tmpname() -- get a temporary file name to store output | ||
local exit_code = os.execute (command.." &> " .. n) | ||
local result = utils.read_file(n) | ||
os.remove(n) | ||
|
||
return result, exit_code / 256 | ||
end | ||
|
||
function _M.start_kong() | ||
return _M.os_execute(KONG_BIN.." -c "..TEST_CONF_FILE.." start") | ||
end | ||
|
||
function _M.stop_kong() | ||
return _M.os_execute(KONG_BIN.." -c "..TEST_CONF_FILE.." stop") | ||
end | ||
|
||
function _M.prepare_db() | ||
-- 1. Migrate our keyspace | ||
migrations:migrate(function(_, err) | ||
if err then | ||
error(err) | ||
end | ||
end) | ||
|
||
-- 2. Prepare statements | ||
local err = dao_factory:prepare() | ||
if err then | ||
error(err) | ||
end | ||
|
||
-- 3. Seed DB with our default data. This will throw any necessary error | ||
faker:seed() | ||
end | ||
|
||
function _M.reset_db() | ||
migrations:reset(function(_, err) | ||
if err then | ||
error(err) | ||
end | ||
end) | ||
end | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.