Loading bin/ruby-build +5 −5 Original line number Diff line number Diff line Loading @@ -147,9 +147,9 @@ verify_checksum() { # If there's no MD5 support, return success [ -n "$HAS_MD5_SUPPORT" ] || return 0 # If the specified filename doesn't exist, return failure # If the specified filename doesn't exist, return success local filename="$1" [ -e "$filename" ] || return 1 [ -e "$filename" ] || return 0 # If there's no expected checksum, return success local expected_checksum="$2" Loading Loading @@ -236,9 +236,9 @@ symlink_tarball_from_cache() { local cached_package_filename="${RUBY_BUILD_CACHE_PATH}/$package_filename" local checksum="$2" { verify_checksum "$cached_package_filename" "$checksum" ln -s "$cached_package_filename" "$package_filename" } >&4 2>&1 || return 1 [ -e "$cached_package_filename" ] || return 1 verify_checksum "$cached_package_filename" "$checksum" >&4 2>&1 || return 1 ln -s "$cached_package_filename" "$package_filename" >&4 2>&1 || return 1 } download_tarball() { Loading test/cache.bats 0 → 100644 +89 −0 Original line number Diff line number Diff line #!/usr/bin/env bats load test_helper export RUBY_BUILD_SKIP_MIRROR=1 export RUBY_BUILD_CACHE_PATH="$TMP/cache" setup() { mkdir "$RUBY_BUILD_CACHE_PATH" } @test "packages are saved to download cache" { stub md5 true stub curl "-*S* : cat package-1.0.0.tar.gz" install_fixture definitions/without-checksum [ "$status" -eq 0 ] [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] unstub curl unstub md5 } @test "cached package without checksum" { stub md5 true stub curl cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH" install_fixture definitions/without-checksum [ "$status" -eq 0 ] [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] unstub curl unstub md5 } @test "cached package with valid checksum" { stub md5 true "echo 83e6d7725e20166024a1eb74cde80677" stub curl cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH" install_fixture definitions/with-checksum [ "$status" -eq 0 ] [ -x "${INSTALL_ROOT}/bin/package" ] [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] unstub curl unstub md5 } @test "cached package with invalid checksum falls back to mirror and updates cache" { export RUBY_BUILD_SKIP_MIRROR= local checksum="83e6d7725e20166024a1eb74cde80677" stub md5 true "echo invalid" "echo $checksum" stub curl "-*I* : true" "-*S* http://?*/$checksum : cat package-1.0.0.tar.gz" touch "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" install_fixture definitions/with-checksum [ "$status" -eq 0 ] [ -x "${INSTALL_ROOT}/bin/package" ] [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] diff -q "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" "${FIXTURE_ROOT}/package-1.0.0.tar.gz" unstub curl unstub md5 } @test "nonexistent cache directory is ignored" { stub md5 true stub curl "-*S* : cat package-1.0.0.tar.gz" export RUBY_BUILD_CACHE_PATH="${TMP}/nonexistent" install_fixture definitions/without-checksum [ "$status" -eq 0 ] [ -x "${INSTALL_ROOT}/bin/package" ] [ ! -d "$RUBY_BUILD_CACHE_PATH" ] unstub curl unstub md5 } test/test_helper.bash +1 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ stub() { export PATH="${BATS_TEST_DIRNAME}/stubs/${program}:$PATH" rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run" touch "${TMP}/${program}-stub-plan" for arg in "$@"; do printf "%s\n" "$arg" >> "${TMP}/${program}-stub-plan"; done } Loading Loading
bin/ruby-build +5 −5 Original line number Diff line number Diff line Loading @@ -147,9 +147,9 @@ verify_checksum() { # If there's no MD5 support, return success [ -n "$HAS_MD5_SUPPORT" ] || return 0 # If the specified filename doesn't exist, return failure # If the specified filename doesn't exist, return success local filename="$1" [ -e "$filename" ] || return 1 [ -e "$filename" ] || return 0 # If there's no expected checksum, return success local expected_checksum="$2" Loading Loading @@ -236,9 +236,9 @@ symlink_tarball_from_cache() { local cached_package_filename="${RUBY_BUILD_CACHE_PATH}/$package_filename" local checksum="$2" { verify_checksum "$cached_package_filename" "$checksum" ln -s "$cached_package_filename" "$package_filename" } >&4 2>&1 || return 1 [ -e "$cached_package_filename" ] || return 1 verify_checksum "$cached_package_filename" "$checksum" >&4 2>&1 || return 1 ln -s "$cached_package_filename" "$package_filename" >&4 2>&1 || return 1 } download_tarball() { Loading
test/cache.bats 0 → 100644 +89 −0 Original line number Diff line number Diff line #!/usr/bin/env bats load test_helper export RUBY_BUILD_SKIP_MIRROR=1 export RUBY_BUILD_CACHE_PATH="$TMP/cache" setup() { mkdir "$RUBY_BUILD_CACHE_PATH" } @test "packages are saved to download cache" { stub md5 true stub curl "-*S* : cat package-1.0.0.tar.gz" install_fixture definitions/without-checksum [ "$status" -eq 0 ] [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] unstub curl unstub md5 } @test "cached package without checksum" { stub md5 true stub curl cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH" install_fixture definitions/without-checksum [ "$status" -eq 0 ] [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] unstub curl unstub md5 } @test "cached package with valid checksum" { stub md5 true "echo 83e6d7725e20166024a1eb74cde80677" stub curl cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH" install_fixture definitions/with-checksum [ "$status" -eq 0 ] [ -x "${INSTALL_ROOT}/bin/package" ] [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] unstub curl unstub md5 } @test "cached package with invalid checksum falls back to mirror and updates cache" { export RUBY_BUILD_SKIP_MIRROR= local checksum="83e6d7725e20166024a1eb74cde80677" stub md5 true "echo invalid" "echo $checksum" stub curl "-*I* : true" "-*S* http://?*/$checksum : cat package-1.0.0.tar.gz" touch "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" install_fixture definitions/with-checksum [ "$status" -eq 0 ] [ -x "${INSTALL_ROOT}/bin/package" ] [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] diff -q "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" "${FIXTURE_ROOT}/package-1.0.0.tar.gz" unstub curl unstub md5 } @test "nonexistent cache directory is ignored" { stub md5 true stub curl "-*S* : cat package-1.0.0.tar.gz" export RUBY_BUILD_CACHE_PATH="${TMP}/nonexistent" install_fixture definitions/without-checksum [ "$status" -eq 0 ] [ -x "${INSTALL_ROOT}/bin/package" ] [ ! -d "$RUBY_BUILD_CACHE_PATH" ] unstub curl unstub md5 }
test/test_helper.bash +1 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ stub() { export PATH="${BATS_TEST_DIRNAME}/stubs/${program}:$PATH" rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run" touch "${TMP}/${program}-stub-plan" for arg in "$@"; do printf "%s\n" "$arg" >> "${TMP}/${program}-stub-plan"; done } Loading