Skip to content
Myr

[Fix] `nvm_get_arch`: proper value for alpine linux

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andrius Solopovas · committed by Jordan Harband · parent b64e547 · Browse files · 3 files+139 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+139 added−3 removed

  • tests:+94 added−0 removed
  • other:+45 added−3 removed

3 files+139 added−3 removed

modified:.github/workflows/windows-npm.yml+41 added-3 removed
added:test/fast/Unit tests/nvm_get_arch_unofficial+94 added
1#!/bin/sh23# Save the PATH as it was when the test started to restore it when it finishes4ORIG_PATH="${PATH}"56cleanup() {7 # Restore the PATH as it was when the test started8 export PATH="${ORIG_PATH}"9 rm -rf "${TMP_DIR}"10}1112die() {13 cleanup14 echo "$@"15 exit 116}1718. ../../../nvm.sh1920# Sets the PATH for these tests to include the symlinks to the mocked binaries21export PATH=".:${PATH}"2223TMP_DIR=$(mktemp -d)24CHROOT_WITH_ALPINE="$TMP_DIR/with_alpine"25CHROOT_WITHOUT_ALPINE="$TMP_DIR/without_alpine"2627setup_chroot() {28 chroot_dir=$12930 # Directories31 mkdir -p "${chroot_dir}/etc"32 mkdir -p "${chroot_dir}/bin"33 mkdir -p "${chroot_dir}/usr/bin"34 mkdir -p "${chroot_dir}/lib64"35 mkdir -p "${chroot_dir}/dev"3637 # Files and binaries38 cp ../../../nvm.sh "${chroot_dir}/"39 cp /bin/sh /usr/bin/dirname "${chroot_dir}/bin/"40 [ "${chroot_dir}" = "${CHROOT_WITH_ALPINE}" ] && touch "${chroot_dir}/etc/alpine-release"4142 # Libraries43 for binary in /bin/sh /usr/bin/dirname; do44 for lib in $(ldd $binary | awk '{print $3}' | grep "^/"); do45 dir=$(dirname "${lib}")46 mkdir -p "${chroot_dir}${dir}"47 cp "${lib}" "${chroot_dir}${dir}/"48 done49 done5051 # Dynamic linker52 cp /lib64/ld-linux-x86-64.so.2 "${chroot_dir}/lib64/"5354 # /dev/null55 sudo mknod "${chroot_dir}/dev/null" c 1 356}5758setup_chroot "${CHROOT_WITH_ALPINE}"59setup_chroot "${CHROOT_WITHOUT_ALPINE}"6061# Run tests in chroot environments62ARCH_WITH_ALPINE=$(sudo chroot "${CHROOT_WITH_ALPINE}" /bin/sh -c ". ./nvm.sh && nvm_get_arch")63[ "${ARCH_WITH_ALPINE}" = "x64-musl" ] || die "Expected x64-musl for alpine environment but got ${ARCH_WITH_ALPINE}"6465ARCH_WITHOUT_ALPINE=$(sudo chroot "${CHROOT_WITHOUT_ALPINE}" /bin/sh -c ". ./nvm.sh && nvm_get_arch")66[ "${ARCH_WITHOUT_ALPINE}" != "x64-musl" ] || die "Did not expect x64-musl for non-alpine environment"6768# Run tests for nvm ls-remote69test_default_ls_remote() {70 mock_response='N/A'71 result=$(NVM_NODEJS_ORG_MIRROR='http://nonexistent-url' nvm ls-remote 18)72 if [ "${result}" = "${mock_response}" ]; then73 die "Test failed: Expected '${mock_response}' for but got '${result}'"74 else75 echo "Test passed"76 fi77}7879test_unofficial_mirror_ls_remote() {80 mock_response='v18.18.0 (LTS: Hydrogen)'81 result=$(NVM_NODEJS_ORG_MIRROR='https://unofficial-builds.nodejs.org/download/release' nvm ls-remote 18.18.0 | sed -e 's/^[[:space:]]*//')82 result=$(echo "${result}" | sed 's/\x1b\[[0-9;]*m//g')8384 if [ "${result}" = "${mock_response}" ]; then85 echo "Test passed"86 else87 die "Test failed: Expected '${mock_response}' but got '${result}'"88 fi89}9091test_default_ls_remote92test_unofficial_mirror_ls_remote9394cleanup
modified:nvm.sh+4 added
1963 unmodified lines
1964 NVM_ARCH=armv7l1965 HOST_ARCH=armv7l1966 fi19671968 if [ -f "/etc/alpine-release" ]; then1969 NVM_ARCH=x64-musl1970 fi19711972 nvm_echo "${NVM_ARCH}"1973}19741975nvm_get_minor_version() {
2456 unmodified lines