Automatic installation in use command
parent
2c411478f3
commit
25ae0f7120
|
@ -16,9 +16,13 @@ version="$(\find "$DCTLENV_ROOT/versions" -type d -exec basename {} \; \
|
|||
| head -n 1
|
||||
)"
|
||||
|
||||
[ -n "$version" ] \
|
||||
&& log_debug "Found version: $version" \
|
||||
|| log_error "No installed versions of driftctl matched '$1'"
|
||||
if [ -n "$version" ]; then
|
||||
log_debug "Found version: $version"
|
||||
else
|
||||
echo "No installed versions of driftctl matched '$1', let's install it"
|
||||
$(dctlenv-install $1 1>/dev/null) || log_error "Installation of version $1 failed"
|
||||
version=$1
|
||||
fi
|
||||
|
||||
target_path="$DCTLENV_ROOT/versions/$version"
|
||||
[ -f "$target_path/driftctl" ] \
|
||||
|
|
|
@ -31,13 +31,18 @@ setup() {
|
|||
assert_output 'usage: dctlenv use [<version>]'
|
||||
}
|
||||
|
||||
@test "dctlenv use [<version>]: prints an error message if we try to use a non-installed version" {
|
||||
@test "dctlenv use [<version>]: prints an error message if we try to use a non-installed version that fails to install" {
|
||||
mkdir -p "$DCTLENV_TMPDIR/versions/0.3.1"
|
||||
|
||||
run dctlenv use 0.3.0
|
||||
dctlenv-install() { exit 1; }; export -f dctlenv-install;
|
||||
|
||||
run dctlenv use 0.0.0
|
||||
|
||||
assert_failure
|
||||
assert_output "No installed versions of driftctl matched '0.3.0'"
|
||||
assert_output <<OUT
|
||||
No installed versions of driftctl matched '0.0.0', let's install it
|
||||
Installation of version 0.0.0 failed
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "dctlenv use [<version>]: prints an error message if we try to use a version where its binary is not present" {
|
||||
|
@ -75,6 +80,27 @@ Switching completed
|
|||
OUT
|
||||
}
|
||||
|
||||
@test "dctlenv use [<version>]: prints a success message if we successfuly install and use a non-installed version" {
|
||||
mkdir -p "$DCTLENV_TMPDIR/versions/0.3.1"
|
||||
|
||||
dctlenv-install() {
|
||||
mkdir -p "$DCTLENV_TMPDIR/versions/0.3.0"
|
||||
touch "$DCTLENV_TMPDIR/versions/0.3.0/driftctl"
|
||||
chmod +x $DCTLENV_TMPDIR/versions/0.3.0/driftctl
|
||||
exit 0
|
||||
}; export -f dctlenv-install;
|
||||
driftctl() { exit 0; }; export -f driftctl;
|
||||
|
||||
run dctlenv use 0.3.0
|
||||
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
No installed versions of driftctl matched '0.3.0', let's install it
|
||||
Switching version to v0.3.0
|
||||
Switching completed
|
||||
OUT
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -rf "$DCTLENV_TMPDIR"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue