2016-08-11 14:10:41 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
cleanup () {
|
2016-08-11 16:45:11 +08:00
|
|
|
unset -f nvm_download nvm_get_checksum_alg nvm_get_mirror
|
2016-08-11 14:10:41 +08:00
|
|
|
}
|
2016-11-07 03:34:36 +08:00
|
|
|
die () { echo "$@" ; cleanup ; exit 1; }
|
2016-08-11 14:10:41 +08:00
|
|
|
|
2016-08-11 16:45:11 +08:00
|
|
|
set +e # TODO: fix
|
2016-11-04 13:15:18 +08:00
|
|
|
\. ../../../nvm.sh
|
2016-08-11 16:45:11 +08:00
|
|
|
set -e
|
|
|
|
|
|
|
|
nvm_get_mirror() {
|
|
|
|
echo "mirror-${1}-${2}"
|
|
|
|
}
|
|
|
|
|
|
|
|
set +ex # needed to capture error output
|
|
|
|
OUTPUT="$(nvm_get_checksum 2>&1 >/dev/null)"
|
|
|
|
EXPECTED_OUTPUT='supported flavors: node, iojs'
|
|
|
|
EXIT_CODE="$(nvm_get_checksum >/dev/null 2>&1 ; echo $?)"
|
|
|
|
set -ex
|
|
|
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected error output >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
|
|
|
|
[ "${EXIT_CODE}" = 2 ] || die "expected exit code 2, got ${EXIT_CODE}"
|
2016-08-11 14:10:41 +08:00
|
|
|
|
|
|
|
nvm_download() {
|
|
|
|
echo "ERROR_FAILED_MATCH no_match more fields"
|
|
|
|
echo "${3} bar.tar.baz more fields"
|
|
|
|
}
|
|
|
|
|
|
|
|
nvm_get_checksum_alg() {
|
|
|
|
echo 'sha-256'
|
|
|
|
}
|
2016-08-11 16:45:11 +08:00
|
|
|
OUTPUT="$(nvm_get_checksum node std foo bar baz)"
|
|
|
|
EXPECTED_OUTPUT="mirror-node-std/foo/SHASUMS256.txt"
|
2016-08-11 14:10:41 +08:00
|
|
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
|
|
|
|
|
|
|
|
nvm_get_checksum_alg() {
|
|
|
|
echo 'sha-1'
|
|
|
|
}
|
2016-08-11 16:45:11 +08:00
|
|
|
OUTPUT="$(nvm_get_checksum iojs std foo bar baz)"
|
|
|
|
EXPECTED_OUTPUT="mirror-iojs-std/foo/SHASUMS.txt"
|
2016-08-11 14:10:41 +08:00
|
|
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
|
|
|
|
|
|
|
|
cleanup
|