Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli) add --yes flag to 'kong migrations' #3189

Merged
merged 1 commit into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion kong/cmd/migrations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ local function execute(args)
db_infos.desc, db_infos.name)
end
elseif args.command == "reset" then
if confirm("Are you sure? This operation is irreversible.") then
if args.yes
or confirm("Are you sure? This operation is irreversible.")
then
dao:drop_schema()
log("Schema successfully reset")
else
Expand All @@ -67,6 +69,7 @@ The available commands are:

Options:
-c,--conf (optional string) configuration file
-y,--yes assume "yes" to prompts and run non-interactively
]]

return {
Expand Down
80 changes: 80 additions & 0 deletions spec/02-integration/02-cmd/10-migrations_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
local helpers = require "spec.helpers"
local pl_utils = require "pl.utils"


local dao = helpers.dao -- postgreSQL DAO (faster to test this command)


describe("kong migrations", function()
describe("reset", function()
before_each(function()
assert(dao:run_migrations())
end)

teardown(function()
dao:drop_schema()
end)

it("runs interactively by default", function()
local answers = {
"y",
"Y",
"yes",
"YES",
}

for _, answer in ipairs(answers) do
local cmd = string.format(helpers.unindent [[
echo %s | %s migrations reset
]], answer, helpers.bin_path)

local ok, _, stdout, stderr = pl_utils.executeex(cmd)
assert.is_true(ok)
assert.equal("", stderr)
assert.matches("Are you sure? This operation is irreversible. [Y/n]",
stdout, nil, true)
assert.matches("Schema successfully reset", stdout, nil, true)
assert(dao:run_migrations())
end
end)

it("cancels when ran interactively", function()
local answers = {
"n",
"N",
"no",
"NO",
}

for _, answer in ipairs(answers) do
local cmd = string.format(helpers.unindent [[
echo %s | %s migrations reset
]], answer, helpers.bin_path)
local ok, _, stdout, stderr = pl_utils.executeex(cmd)
assert.is_true(ok)
assert.equal("", stderr)
assert.matches("Are you sure? This operation is irreversible. [Y/n]",
stdout, nil, true)
assert.matches("Canceled", stdout, nil, true)
end
end)

it("runs non-interactively with --yes", function()
local ok, stderr, stdout = helpers.kong_exec("migrations reset --yes")
assert.is_true(ok)
assert.is_equal("", stderr)
assert.not_matches("Are you sure? This operation is irreversible. [Y/n]",
stdout, nil, true)
assert.matches("Schema successfully reset", stdout, nil, true)
end)

it("runs non-interactively with -y", function()
local ok, stderr, stdout = helpers.kong_exec("migrations reset -y")
assert.is_true(ok)
assert.is_equal("", stderr)
assert.not_matches("Are you sure? This operation is irreversible. [Y/n]",
stdout, nil, true)
assert.matches("Schema successfully reset", stdout, nil, true)
end)
end)
end)