Skip to content

Commit

Permalink
[Tests] nvm_get_download_slug: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 3, 2021
1 parent 328dd50 commit 81fc056
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions test/fast/Unit tests/nvm_get_download_slug
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/sh

cleanup() {
unset nvm_get_os
unset nvm_get_arch
}

die () { cleanup; echo "$@" ; exit 1; }

\. ../../../nvm.sh

[ "$(nvm_get_download_slug 2>/dev/null ; echo $?)" = '1' ] || die 'invalid flavor did not fail with exit code 1'
[ "$(nvm_get_download_slug 2>&1)" = 'supported flavors: node, iojs' ] || die 'invalid flavor did not fail with expected message'

[ "$(nvm_get_download_slug node 2>/dev/null ; echo $?)" = '2' ] || die 'invalid kind did not fail with exit code 2'
[ "$(nvm_get_download_slug node 2>&1)" = 'supported kinds: binary, source' ] || die 'invalid kind did not fail with expected message'
[ "$(nvm_get_download_slug iojs 2>/dev/null ; echo $?)" = '2' ] || die 'invalid kind did not fail with exit code 2'
[ "$(nvm_get_download_slug iojs 2>&1)" = 'supported kinds: binary, source' ] || die 'invalid kind did not fail with expected message'

nvm_get_os() {
echo omgOS
}
nvm_get_arch() {
echo nemesis
}

ACTUAL="$(nvm_get_download_slug node binary 1.2.3)"
EXPECTED='node-1.2.3-omgOS-nemesis'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
ACTUAL="$(nvm_get_download_slug iojs binary 1.2.3)"
EXPECTED='iojs-1.2.3-omgOS-nemesis'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"

ACTUAL="$(nvm_get_download_slug node source 1.2.3)"
EXPECTED="node-1.2.3"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
ACTUAL="$(nvm_get_download_slug iojs source 1.2.3)"
EXPECTED="iojs-1.2.3"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"

nvm_get_arch() {
echo armv6l
}
ACTUAL="$(nvm_get_download_slug node binary 1.2.3)"
EXPECTED='node-1.2.3-omgOS-arm-pi'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
ACTUAL="$(nvm_get_download_slug iojs binary 1.2.3)"
EXPECTED='iojs-1.2.3-omgOS-arm-pi'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"

ACTUAL="$(nvm_get_download_slug node source 1.2.3)"
EXPECTED="node-1.2.3"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
ACTUAL="$(nvm_get_download_slug iojs source 1.2.3)"
EXPECTED="iojs-1.2.3"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"

nvm_get_arch() {
echo armv7l
}
ACTUAL="$(nvm_get_download_slug node binary 1.2.3)"
EXPECTED='node-1.2.3-omgOS-arm-pi'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
ACTUAL="$(nvm_get_download_slug iojs binary 1.2.3)"
EXPECTED='iojs-1.2.3-omgOS-arm-pi'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"

ACTUAL="$(nvm_get_download_slug node source 1.2.3)"
EXPECTED="node-1.2.3"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
ACTUAL="$(nvm_get_download_slug iojs source 1.2.3)"
EXPECTED="iojs-1.2.3"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"

nvm_get_os() {
echo darwin
}
nvm_get_arch() {
echo nemesis
}
ACTUAL="$(nvm_get_download_slug node binary 15.99.99)"
EXPECTED='node-15.99.99-darwin-nemesis'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
ACTUAL="$(nvm_get_download_slug iojs binary 15.99.99)"
EXPECTED='iojs-15.99.99-darwin-nemesis'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"

ACTUAL="$(nvm_get_download_slug node source 15.99.99)"
EXPECTED="node-15.99.99"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
ACTUAL="$(nvm_get_download_slug iojs source 15.99.99)"
EXPECTED="iojs-15.99.99"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"

nvm_get_arch() {
echo arm64
}
ACTUAL="$(nvm_get_download_slug node binary 15.99.99)"
EXPECTED='node-15.99.99-darwin-x64'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
ACTUAL="$(nvm_get_download_slug iojs binary 15.99.99)"
EXPECTED='iojs-15.99.99-darwin-x64'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"

ACTUAL="$(nvm_get_download_slug node source 15.99.99)"
EXPECTED="node-15.99.99"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
ACTUAL="$(nvm_get_download_slug iojs source 15.99.99)"
EXPECTED="iojs-15.99.99"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"

0 comments on commit 81fc056

Please sign in to comment.