Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/tfenv-exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function realpath-relative-to() {
export -f realpath-relative-to;

function tfenv-exec() {
for _arg in "${@}"; do
for _arg in ${@+"$@"}; do
if [[ "${_arg}" == -chdir=* ]]; then
chdir="${_arg#-chdir=}";
log 'debug' "Found -chdir arg: ${chdir}";
Expand Down
40 changes: 40 additions & 0 deletions test/test_shim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

# Source common test setup
source "$(dirname "${0}")/test_common.sh";

#####################
# Begin Script Body #
#####################

declare -a errors=();

log 'info' '### Test Suite: terraform shim';

log 'info' '## terraform shim: passes through to terraform (without args)';
cleanup || log 'error' 'Cleanup failed?!';
(
tfenv install 1.6.1 || exit 1;
tfenv use 1.6.1 || exit 1;
declare output;
output="$(terraform 2>&1 || true)";
# https://github.com/tfutils/tfenv/issues/532
echo "${output}" | grep -q 'unbound variable' && exit 1;
echo "${output}" | grep -q 'Usage: terraform' || exit 1;
) && log 'info' '## terraform (no args): passed' \
|| error_and_proceed 'terraform with no args crashed or did not show usage';

log 'info' '## terraform shim: passes through to terraform (with args)';
(
tfenv install 1.6.1 || exit 1;
tfenv use 1.6.1 || exit 1;
declare output;
output="$(terraform version -json)" || exit 1;
echo "${output}" | grep -q 'terraform_version' || exit 1;
echo "${output}" | grep -q '1.6.1' || exit 1;
) && log 'info' '## terraform shim: arguments are passed through: passed' \
|| error_and_proceed 'terraform arguments were not passed through';

finish_tests 'shim';

exit 0;