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

schlueter: Fix tfenv list in virgin environments #236

Merged
merged 1 commit into from
Feb 6, 2021
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
13 changes: 10 additions & 3 deletions libexec/tfenv-list
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ done;
[[ -x "${TFENV_ROOT}/versions" && -r "${TFENV_ROOT}/versions" ]] \
|| log 'error' "tfenv versions directory is inaccessible: ${TFENV_ROOT}/versions";

version_name="$(tfenv-version-name)" \
&& log 'debug' "tfenv-version-name reported: ${version_name}" \
|| log 'error' "tfenv-version-name failed";
version_name="$(tfenv-version-name 2>/dev/null || true)" \
&& log 'debug' "tfenv-version-name reported: ${version_name}";
export version_name;

if [ -z "${TFENV_TERRAFORM_VERSION:-""}" ]; then
Expand All @@ -82,9 +81,13 @@ else
fi
export version_source;

# Register for whether a default terraform version has yet been set
declare -i default_set=0;

print_version () {
if [ "${1}" == "${version_name}" ]; then
echo "* ${1} (set by ${version_source})";
default_set=1
else
echo " ${1}";
fi;
Expand All @@ -101,3 +104,7 @@ log 'debug' 'Printing versions...';
for local_version in ${local_versions[@]}; do
print_version "${local_version}";
done;

[ "${default_set}" -eq 0 ] && log 'info' "No default set. Set with 'tfenv use <version>'";

exit 0;
15 changes: 10 additions & 5 deletions test/test_list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ for v in 0.7.2 0.7.13 0.9.1 0.9.2 0.9.11; do
|| error_and_proceed "Install of version ${v} failed";
done;

tfenv use 0.9.11
log 'info' '## Ensuring tfenv list success with no default set';
tfenv list \
&& log 'debug' "List succeeded with no default set" \
|| error_and_proceed "List failed with no default set";

log 'info' '## Comparing "tfenv list" to expectations';
tfenv use 0.9.11;

log 'info' '## Comparing "tfenv list" with default set';
result="$(tfenv list)";
expected="$(cat << EOS
* 0.9.11 (set by $(tfenv version-file))
Expand All @@ -73,9 +78,9 @@ expected="$(cat << EOS
EOS
)";

if [ "${expected}" != "${result}" ]; then
error_and_proceed "List mismatch.\nExpected:\n${expected}\nGot:\n${result}";
fi;
[ "${expected}" == "${result}" ] \
&& log 'info' 'List matches expectation.' \
|| error_and_proceed "List mismatch.\nExpected:\n${expected}\nGot:\n${result}";

if [ "${#errors[@]}" -gt 0 ]; then
log 'warn' "===== The following list tests failed =====";
Expand Down