diff --git a/kong/cmd/utils/inject_directives.lua b/kong/cmd/utils/inject_directives.lua index 2fb11eddf47..f01ce0c732e 100644 --- a/kong/cmd/utils/inject_directives.lua +++ b/kong/cmd/utils/inject_directives.lua @@ -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 diff --git a/spec/01-unit/28-inject_directives_spec.lua b/spec/01-unit/28-inject_directives_spec.lua index 81562bbb3cf..27ba61fe49b 100644 --- a/spec/01-unit/28-inject_directives_spec.lua +++ b/spec/01-unit/28-inject_directives_spec.lua @@ -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" @@ -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", @@ -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) @@ -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", @@ -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