-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Add unit tests for nvm_is_version_installed
- Loading branch information
1 parent
d9b11ba
commit 8d21c86
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/sh | ||
|
||
cleanup () { | ||
rm -rf "$NVM_DIR" | ||
unset -f die cleanup | ||
unset NVM_DIR NODE_PATH | ||
} | ||
die () { echo "$@" ; cleanup ; exit 1; } | ||
|
||
\. ../../../nvm.sh | ||
|
||
set -ex | ||
|
||
NVM_DIR=$(mktemp -d) | ||
NODE_PATH="$NVM_DIR/versions/node" | ||
mkdir -p "$NODE_PATH" | ||
if [ -z "$NODE_PATH" ]; then | ||
die 'Unable to create temporary folder' | ||
fi | ||
|
||
# nvm_is_version_installed is available | ||
type nvm_is_version_installed > /dev/null 2>&1 || die 'nvm_is_version_installed is not available' | ||
|
||
# nvm_is_version_installed with no parameter fails | ||
! nvm_is_version_installed || die 'nvm_is_version_installed without parameter should fail' | ||
|
||
# nvm_is_version_installed fails with non existing version | ||
! nvm_is_version_installed 12.0.0 || die 'nvm_is_version_installed 12.0.0 should fail with non existing version' | ||
|
||
# nvm_is_version_installed fails with non executable existing version | ||
mkdir -p "$NODE_PATH/12.0.0/bin" && cd "$NODE_PATH/12.0.0/bin" && touch "$NODE_PATH/12.0.0/bin/node" | ||
! nvm_is_version_installed 12.0.0 || die 'nvm_is_version_installed 12.0.0 should fail with non executable existing version' | ||
|
||
# nvm_is_version_installed whould work | ||
chmod +x "$NODE_PATH/12.0.0/bin/node" | ||
nvm_is_version_installed 12.0.0 || die 'nvm_is_version_installed 12.0.0 should work' | ||
|
||
cleanup |