diff --git a/libexec/dctlenv-use b/libexec/dctlenv-use index 475d2cc..a64dba4 100755 --- a/libexec/dctlenv-use +++ b/libexec/dctlenv-use @@ -3,8 +3,6 @@ set -uo pipefail [ "$#" -gt 1 ] && log_error "Need 1 version instead of $#" 'usage: dctlenv use []' -[ -d "$DCTLENV_ROOT/versions" ] || log_error 'No versions of driftctl installed. Please install one with: dctlenv install []' - version_requested="${1:-""}" [ -n "$version_requested" ] || log_error 'Version is not specified' 'usage: dctlenv use []' @@ -13,7 +11,7 @@ if [[ $version_requested == "latest" ]]; then fi log_debug "Searching $DCTLENV_ROOT/versions for version matching $version_requested" -version="$(\find "$DCTLENV_ROOT/versions" -type d -exec basename {} \; \ +version="$(\find "$DCTLENV_ROOT/versions" -type d -exec basename {} \; 2>/dev/null \ | tail -n +2 \ | sort -t'.' -k 1nr,1 -k 2nr,2 -k 3nr,3 \ | grep -e "$version_requested" \ diff --git a/test/dctlenv-use.bats b/test/dctlenv-use.bats index c51de6a..ed2f97d 100644 --- a/test/dctlenv-use.bats +++ b/test/dctlenv-use.bats @@ -27,13 +27,6 @@ setup() { assert_output 'usage: dctlenv use []' } -@test "dctlenv use []: prints an error message if there is no version installed" { - run dctlenv use 0.3.1 - - assert_failure - assert_output 'No versions of driftctl installed. Please install one with: dctlenv install []' -} - @test "dctlenv use []: prints an error message if we don't specified a version to use" { mkdir -p "$DCTLENV_TMPDIR/versions/0.3.1" @@ -134,6 +127,25 @@ Switching completed OUT } +@test "dctlenv use []: can install and use driftctl for a new dctlenv utilisation" { + dctlenv-install() { + mkdir -p "$DCTLENV_TMPDIR/versions/0.3.1" + touch "$DCTLENV_TMPDIR/versions/0.3.1/driftctl" + chmod +x $DCTLENV_TMPDIR/versions/0.3.1/driftctl + exit 0 + }; export -f dctlenv-install; + driftctl() { exit 0; }; export -f driftctl; + + run dctlenv use latest + + assert_success + assert_output <