Install and use driftctl on new dctlenv installation
parent
6cbb21a214
commit
0d96fa467c
|
@ -3,8 +3,6 @@ set -uo pipefail
|
|||
|
||||
[ "$#" -gt 1 ] && log_error "Need 1 version instead of $#" 'usage: dctlenv use [<version>]'
|
||||
|
||||
[ -d "$DCTLENV_ROOT/versions" ] || log_error 'No versions of driftctl installed. Please install one with: dctlenv install [<version>]'
|
||||
|
||||
version_requested="${1:-""}"
|
||||
[ -n "$version_requested" ] || log_error 'Version is not specified' 'usage: dctlenv use [<version>]'
|
||||
|
||||
|
@ -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" \
|
||||
|
|
|
@ -27,13 +27,6 @@ setup() {
|
|||
assert_output 'usage: dctlenv use [<version>]'
|
||||
}
|
||||
|
||||
@test "dctlenv use [<version>]: 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 [<version>]'
|
||||
}
|
||||
|
||||
@test "dctlenv use [<version>]: 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 [<version>]: 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 <<OUT
|
||||
No installed versions of driftctl matched '0.3.1', let's install it
|
||||
Switching version to v0.3.1
|
||||
Switching completed
|
||||
OUT
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -rf "$DCTLENV_TMPDIR"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue