Skip to content

Commit

Permalink
resty isn't necessarily in the position -1, so add it explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
catbro666 committed Jun 26, 2023
1 parent c3d9d69 commit 308a3f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
4 changes: 3 additions & 1 deletion kong/cmd/utils/inject_directives.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ local function construct_cmd(conf)

-- terminate the recursion
local cmd = {"KONG_CLI_RESPAWNED=1"}
for i = -1, #_G.cli_args do
-- resty isn't necessarily in the position -1
table.insert(cmd, "resty")
for i = 0, #_G.cli_args do
table.insert(cmd, _G.cli_args[i])
end

Expand Down
20 changes: 6 additions & 14 deletions spec/01-unit/28-inject_directives_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
local pl_path = require "pl.path"
local pl_utils = require "pl.utils"
local pl_stringx = require "pl.stringx"
local helpers = require "spec.helpers"
local conf_loader = require "kong.conf_loader"
local inject_directives = require "kong.cmd.utils.inject_directives"
Expand Down Expand Up @@ -28,12 +26,9 @@ lua_ssl_verify_depth 1;
lua_ssl_trusted_certificate '/usr/local/kong/.ca_combined';
lua_ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
]]
local ok, code, stdout, stderr = pl_utils.executeex("command -v resty")
assert(ok and code == 0, stderr)
local resty_path = pl_stringx.strip(stdout)
local kong_path = cwd .. "/bin/kong"
_G.cli_args = {
[-1] = resty_path,
[-1] = "resty",
[0] = kong_path,
[1] = "vault",
[2] = "get",
Expand All @@ -49,8 +44,8 @@ lua_ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
if strategy == "off" then
expected_main_conf = main_conf_off
end
local expected_cmd = fmt("KONG_CLI_RESPAWNED=1 %s --main-conf \"%s\" --http-conf \"%s\" --stream-conf \"%s\" %s vault get test-env/test --v",
resty_path, expected_main_conf, http_conf, stream_conf, kong_path)
local expected_cmd = fmt("KONG_CLI_RESPAWNED=1 resty --main-conf \"%s\" --http-conf \"%s\" --stream-conf \"%s\" %s vault get test-env/test --v",
expected_main_conf, http_conf, stream_conf, kong_path)
assert.matches(expected_cmd, cmd, nil, true)
end)

Expand All @@ -72,12 +67,9 @@ lua_ssl_verify_depth 1;
lua_ssl_trusted_certificate '%s/servroot/.ca_combined';
lua_ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
]], cwd)
local ok, code, stdout, stderr = pl_utils.executeex("command -v resty")
assert(ok and code == 0, stderr)
local resty_path = pl_stringx.strip(stdout)
local kong_path = cwd .. "/bin/kong"
_G.cli_args = {
[-1] = resty_path,
[-1] = "resty",
[0] = kong_path,
[1] = "vault",
[2] = "get",
Expand All @@ -94,8 +86,8 @@ lua_ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
if strategy == "off" then
expected_main_conf = main_conf_off
end
local expected_cmd = fmt("KONG_CLI_RESPAWNED=1 %s --main-conf \"%s\" --http-conf \"%s\" --stream-conf \"%s\" %s vault get test-env/test --v",
resty_path, expected_main_conf, http_conf, stream_conf, kong_path)
local expected_cmd = fmt("KONG_CLI_RESPAWNED=1 resty --main-conf \"%s\" --http-conf \"%s\" --stream-conf \"%s\" %s vault get test-env/test --v",
expected_main_conf, http_conf, stream_conf, kong_path)
assert.matches(expected_cmd, cmd, nil, true)
end)
end
Expand Down

0 comments on commit 308a3f1

Please sign in to comment.