Skip to content

Commit

Permalink
Merge pull request #11 from opentofuutils/fix/tests
Browse files Browse the repository at this point in the history
Fix test install
  • Loading branch information
Nmishin authored Dec 29, 2023
2 parents 7929473 + 9126f56 commit 2afce4f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: 'Install Dependencies'
run: './test/install_deps.sh'
- name: 'Run all tests'
run: './test/run.sh'
run: 'TOFUENV_GITHUB_TOKEN=${{ secrets.TOFUENV_GITHUB_TOKEN }} ./test/run.sh'
shell: 'bash'

- uses: 'docker/setup-buildx-action@v3'
Expand Down
7 changes: 6 additions & 1 deletion lib/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ function curlw () {
NETRC_OPT="";
fi;

curl ${TLS_OPT} ${NETRC_OPT} "$@";
if [[ ! -z "${TOFUENV_GITHUB_TOKEN:-""}" ]]; then
AUTHORIZATION_HEADER="Authorization: Bearer ${TOFUENV_GITHUB_TOKEN}";
else
AUTHORIZATION_HEADER="";
fi;
curl ${TLS_OPT} -H "${AUTHORIZATION_HEADER}" ${NETRC_OPT} "$@";
};
export -f curlw;

Expand Down
79 changes: 5 additions & 74 deletions test/test_install_and_use.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,45 +85,31 @@ declare -a errors=();
log 'info' '### Test Suite: Install and Use';

tests__desc=(
'latest version'
# 'latest version'
'latest possibly-unstable version'
'latest alpha'
'latest beta'
'latest rc'
'latest possibly-unstable version from 1.6'
'1.6.0-alpha2'
'latest version matching regex'
'specific version'
'specific version with v prefix'
);

tests__kv=(
"$(tofuenv list-remote | grep -e "^[0-9]\+\.[0-9]\+\.[0-9]\+$" | head -n 1),latest"
# "$(tofuenv list-remote | grep -e "^[0-9]\+\.[0-9]\+\.[0-9]\+$" | head -n 1),latest"
"$(tofuenv list-remote | head -n 1),latest:"
"$(tofuenv list-remote | grep 'alpha' | head -n 1),latest:alpha"
"$(tofuenv list-remote | grep 'beta' | head -n 1),latest:beta"
"$(tofuenv list-remote | grep 'rc' | head -n 1),latest:rc"
"$(tofuenv list-remote | grep '^1\.6\.' | head -n 1),latest:^1.6."
'1.6.0-alpha2,latest:^1\.6'
'1.6.0-rc1,1.6.0-alpha1'
'1.6.0-rc1,latest:^1\.6'
'1.6.0-alpha5'
'1.6.0-rc1,v1.6.0-rc1'
);

log 'info' "Kernel under test: $(uname -s)";

if [[ "$(uname -s)" != Darwin* ]]; then
log 'info' "We're not Darwin! Adding legacy tests.";
tests__desc+=(
'legacy latest version matching regex'
'legacy specific version'
);

tests__kv+=(
'1.6.0-rc1,latest:^1.6'
);
else
log 'warn' "We're Darwin! Skipping legacy tests.";
fi;

tests_count=${#tests__desc[@]};

declare desc kv k v test_num;
Expand Down Expand Up @@ -174,61 +160,6 @@ done;
cleanup || log 'error' 'Cleanup failed?!';
log 'info' '## ${HOME}/.opentofu-version Test Preparation';

# 0.12.22 reports itself as 0.12.21 and breaks testing
declare v1="$(tofuenv list-remote | grep -e "^[0-9]\+\.[0-9]\+\.[0-9]\+$" | grep -v '0.12.22' | head -n 2 | tail -n 1)";
declare v2="$(tofuenv list-remote | grep -e "^[0-9]\+\.[0-9]\+\.[0-9]\+$" | grep -v '0.12.22' | head -n 1)";

if [ -f "${HOME}/.opentofu-version" ]; then
log 'info' "Backing up ${HOME}/.opentofu-version to ${HOME}/.opentofu-version.bup";
mv "${HOME}/.opentofu-version" "${HOME}/.opentofu-version.bup";
fi;
log 'info' "Writing ${v1} to ${HOME}/.opentofu-version";
echo "${v1}" > "${HOME}/.opentofu-version";

log 'info' "## \${HOME}/.opentofu-version Test 1/3: Install and Use ( ${v1} )";
test_install_and_use "${v1}" \
&& log info "## \${HOME}/.opentofu-version Test 1/1: ( ${v1} ) succeeded" \
|| error_and_proceed "## \${HOME}/.opentofu-version Test 1/1: ( ${v1} ) failed";

log 'info' "## \${HOME}/.opentofu-version Test 2/3: Override Install with Parameter ( ${v2} )";
test_install_and_use_overridden "${v2}" "${v2}" \
&& log info "## \${HOME}/.opentofu-version Test 2/3: ( ${v2} ) succeeded" \
|| error_and_proceed "## \${HOME}/.opentofu-version Test 2/3: ( ${v2} ) failed";

log 'info' "## \${HOME}/.opentofu-version Test 3/3: Override Use with Parameter ( ${v2} )";
(
tofuenv use "${v2}" || exit 1;
check_default_version "${v2}" || exit 1;
) && log info "## \${HOME}/.opentofu-version Test 3/3: ( ${v2} ) succeeded" \
|| error_and_proceed "## \${HOME}/.opentofu-version Test 3/3: ( ${v2} ) failed";

log 'info' '## \${HOME}/.opentofu-version Test Cleanup';
log 'info' "Deleting ${HOME}/.opentofu-version";
rm "${HOME}/.opentofu-version";
if [ -f "${HOME}/.opentofu-version.bup" ]; then
log 'info' "Restoring backup from ${HOME}/.opentofu-version.bup to ${HOME}/.opentofu-version";
mv "${HOME}/.opentofu-version.bup" "${HOME}/.opentofu-version";
fi;

log 'info' '## Use Auto-Install Test 1/2: (No Input)';
cleanup || log 'error' 'Cleanup failed?!';

(
tofuenv use || exit 1;
check_default_version "$(tofuenv list-remote | grep -e "^[0-9]\+\.[0-9]\+\.[0-9]\+$" | head -n 1)" || exit 1;
) && log info '## Use Auto-Install Test 1/2: (No Input) succeeded' \
|| error_and_proceed '## Use Auto-Install Test 1/2: (No Input) failed';

log 'info' '## Use Auto-Install Test 2/2: (Specific version)';
cleanup || log 'error' 'Cleanup failed?!';

(
tofuenv use 1.0.1 || exit 1;
check_default_version 1.0.1 || exit 1;
) && log info '## Use Auto-Install Test 2/2: (Specific version) succeeded' \
|| error_and_proceed '## Use Auto-Install Test 2/2: (Specific version) failed';


log 'info' 'Install invalid specific version';
cleanup || log 'error' 'Cleanup failed?!';

Expand Down
8 changes: 4 additions & 4 deletions test/test_uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ done;
echo "### Uninstall removes versions directory"
cleanup || error_and_die "Cleanup failed?!"
(
tofuenv install 0.12.1 || exit 1
tofuenv install 0.12.2 || exit 1
tofuenv install 1.6.0-beta5 || exit 1
tofuenv install 1.6.0-beta4 || exit 1
[ -d "./versions" ] || exit 1
tofuenv uninstall 0.12.1 || exit 1
tofuenv uninstall 1.6.0-beta5 || exit 1
[ -d "./versions" ] || exit 1
tofuenv uninstall 0.12.2 || exit 1
tofuenv uninstall 1.6.0-beta4 || exit 1
[ -d "./versions" ] && exit 1 || exit 0
) || error_and_proceed "Removing last version deletes versions directory"

Expand Down
14 changes: 7 additions & 7 deletions test/test_use_latestallowed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ echo "terraform {
(
tofuenv install latest-allowed;
tofuenv use latest-allowed;
check_active_version 1.1.9;
check_active_version 1.6.0-rc1;
) || error_and_proceed 'Latest allowed version does not match';

cleanup || log 'error' 'Cleanup failed?!';
Expand All @@ -86,13 +86,13 @@ cleanup || log 'error' 'Cleanup failed?!';
log 'info' '### Install latest-allowed incomplete version (#.#.<missing>)'

echo "terraform {
required_version = \"~> 0.12\"
required_version = \"~> 1.6\"
}" >> latest_allowed.tf;

(
tofuenv install latest-allowed;
tofuenv use latest-allowed;
check_active_version 0.15.5;
check_active_version 1.6.0-rc1;
) || error_and_proceed 'Latest allowed incomplete-version does not match';

cleanup || log 'error' 'Cleanup failed?!';
Expand All @@ -101,13 +101,13 @@ cleanup || log 'error' 'Cleanup failed?!';
log 'info' '### Install latest-allowed with TOFUENV_AUTO_INSTALL';

echo "terraform {
required_version = \"~> 1.0.0\"
required_version = \"~> 1.6.0-rc1\"
}" >> latest_allowed.tf;
echo 'latest-allowed' > .opentofu-version;

(
TOFUENV_AUTO_INSTALL=true tofu version;
check_active_version 1.0.11;
check_active_version 1.6.0-rc1;
) || error_and_proceed 'Latest allowed auto-installed version does not match';

cleanup || log 'error' 'Cleanup failed?!';
Expand All @@ -117,13 +117,13 @@ log 'info' '### Install latest-allowed with TOFUENV_AUTO_INSTALL & -chdir';

mkdir -p chdir-dir
echo "terraform {
required_version = \"~> 0.14.3\"
required_version = \"~> 1.6.0-rc1\"
}" >> chdir-dir/latest_allowed.tf;
echo 'latest-allowed' > chdir-dir/.opentofu-version

(
TOFUENV_AUTO_INSTALL=true tofu -chdir=chdir-dir version;
check_active_version 0.14.11 chdir-dir;
check_active_version 1.6.0-rc1 chdir-dir;
) || error_and_proceed 'Latest allowed version from -chdir does not match';

cleanup || log 'error' 'Cleanup failed?!';
Expand Down
35 changes: 18 additions & 17 deletions test/test_use_minrequired.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,23 @@ echo "terraform {

cleanup || log 'error' 'Cleanup failed?!';


log 'info' '### Install min-required incomplete version (#.#.<missing>)'

minv='1.3';

echo "terraform {
required_version = \">=${minv}\"
}" >> min_required.tf;

(
tofuenv install min-required;
tofuenv use min-required;
check_active_version "${minv}.0";
) || error_and_proceed 'Min required incomplete-version does not match';

cleanup || log 'error' 'Cleanup failed?!';
# TODO: Enable this test after 1.6.0 will be fully available
#
#log 'info' '### Install min-required incomplete version (#.#.<missing>)'
#
#minv='1.6';
#
#echo "terraform {
# required_version = \">=${minv}\"
#}" >> min_required.tf;
#
#(
# tofuenv install min-required;
# tofuenv use min-required;
# check_active_version "${minv}.0";
#) || error_and_proceed 'Min required incomplete-version does not match';
#
#cleanup || log 'error' 'Cleanup failed?!';


log 'info' '### Install min-required with TOFUENV_AUTO_INSTALL';
Expand All @@ -123,7 +124,7 @@ cleanup || log 'error' 'Cleanup failed?!';

log 'info' '### Install min-required with TOFUENV_AUTO_INSTALL & -chdir';

minv='1.6.0-rc1';
minv='1.6.0-alpha5';

mkdir -p chdir-dir
echo "terraform {
Expand Down

0 comments on commit 2afce4f

Please sign in to comment.