We can install|use|uninstall version that is prefixed with v

main
William Beuil 2021-03-08 11:48:56 +01:00
parent 0d96fa467c
commit cacd45eb62
No known key found for this signature in database
GPG Key ID: BED2072C5C2BF537
7 changed files with 73 additions and 2 deletions

View File

@ -56,7 +56,7 @@ Install a specific version of driftctl.
Available options:
- `x.y.z` to install the exact version of driftctl
- `(v)x.y.z` to install the exact version of driftctl
- `latest` to install the latest version of driftctl
```console
@ -102,13 +102,17 @@ Switch a version to use.
Available options:
- `x.y.z` to install and use the exact version of driftctl
- `(v)x.y.z` to install and use the exact version of driftctl
- `latest` to install and use the latest version of driftctl
```console
$ dctlenv use 0.2.3
Switching version to v0.2.3
Switching completed
$ dctlenv use v0.6.0
Switching version to v0.6.0
Switching completed
```
### `dctlenv list`
@ -139,10 +143,18 @@ $ dctlenv list-remote
Uninstall a specific version of driftctl.
Available options:
- `(v)x.y.z` to uninstall the exact version of driftctl
```console
$ dctlenv uninstall 0.2.3
Uninstall driftctl v0.2.3
driftctl v0.2.3 is successfully uninstalled
$ dctlenv uninstall v0.6.0
Uninstall driftctl v0.6.0
driftctl v0.6.0 is successfully uninstalled
```
### `dctlenv root`

View File

@ -6,6 +6,8 @@ set -uo pipefail
version_requested="${1:-""}"
[ -n "$version_requested" ] || log_error 'Version is not specified' 'usage: dctlenv install [<version>]'
version_requested=$(echo $version_requested | sed 's/^v//')
if [[ $version_requested == "latest" ]]; then
version="$(dctlenv-list-remote | tail -n 1)"
else

View File

@ -6,6 +6,8 @@ set -uo pipefail
version_requested="${1:-""}"
[ -n "$version_requested" ] || log_error 'Version is not specified' 'usage: dctlenv uninstall [<version>]'
version_requested=$(echo $version_requested | sed 's/^v//')
version="$(dctlenv-list 2>/dev/null | sed -E 's/^(\*| )? //g; s/ \(set by .+\)$//' | grep -e "$version_requested" | head -n 1)"
[ -n "$version" ] || log_error "No versions matching '$version_requested' found in local"

View File

@ -6,6 +6,8 @@ set -uo pipefail
version_requested="${1:-""}"
[ -n "$version_requested" ] || log_error 'Version is not specified' 'usage: dctlenv use [<version>]'
version_requested=$(echo $version_requested | sed 's/^v//')
if [[ $version_requested == "latest" ]]; then
version_requested="$(dctlenv-list-remote | tail -n 1)"
fi

View File

@ -148,6 +148,27 @@ Installation of driftctl v0.3.1 successful. To make this your default version, r
OUT
}
@test "dctlenv install [<version>]: prints a success message if it can install v0.3.1" {
uname() { echo "Linux"; }; export -f uname;
curlw() {
mkdir -p "$DCTLENV_TMPDIR/versions/0.3.1"
touch "$DCTLENV_TMPDIR/versions/0.3.1/driftctl_linux_amd64"
(cd "$DCTLENV_TMPDIR/versions/0.3.1"; sha256sum * > "$DCTLENV_TMPDIR/versions/0.3.1/driftctl_SHA256SUMS")
exit 0
}; export -f curlw;
run dctlenv install v0.3.1
assert_success
assert_output <<OUT
Installing driftctl v0.3.1
Downloading release tarball from https://github.com/cloudskiff/driftctl/releases/download/v0.3.1/driftctl_linux_amd64
Downloading SHA256 hashes file from https://github.com/cloudskiff/driftctl/releases/download/v0.3.1/driftctl_SHA256SUMS
SHA256 hash matched!
Installation of driftctl v0.3.1 successful. To make this your default version, run 'dctlenv use 0.3.1'
OUT
}
@test "dctlenv install [<version>]: prints a success message if it can install the latest version" {
uname() { echo "Linux"; }; export -f uname;
curlw() {

View File

@ -55,6 +55,22 @@ driftctl v0.3.1 is successfully uninstalled
OUT
}
@test "dctlenv uninstall [<version>]: prints a success message if it can uninstall v0.3.1" {
mkdir -p "$DCTLENV_TMPDIR/versions/0.3.1"
mkdir -p "$DCTLENV_TMPDIR/versions/0.3.0"
mkdir -p "$DCTLENV_TMPDIR/versions/0.2.3"
touch "$DCTLENV_TMPDIR/versions/0.3.1/driftctl"
run dctlenv uninstall v0.3.1
assert_success
assert_output <<OUT
Uninstall driftctl v0.3.1
driftctl v0.3.1 is successfully uninstalled
OUT
}
teardown() {
rm -rf "$DCTLENV_TMPDIR"
}

View File

@ -85,6 +85,22 @@ Switching completed
OUT
}
@test "dctlenv use [<version>]: prints a success message when switching versions v0.3.1" {
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
driftctl() { exit 0; }; export -f driftctl;
run dctlenv use v0.3.1
assert_success
assert_output <<OUT
Switching version to v0.3.1
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"