mirror of
https://github.com/rbenv/ruby-build.git
synced 2025-09-07 17:51:13 +02:00
Test package cache
This commit is contained in:
parent
d999db787e
commit
d924fceee5
3 changed files with 95 additions and 5 deletions
|
@ -147,9 +147,9 @@ verify_checksum() {
|
||||||
# If there's no MD5 support, return success
|
# If there's no MD5 support, return success
|
||||||
[ -n "$HAS_MD5_SUPPORT" ] || return 0
|
[ -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"
|
local filename="$1"
|
||||||
[ -e "$filename" ] || return 1
|
[ -e "$filename" ] || return 0
|
||||||
|
|
||||||
# If there's no expected checksum, return success
|
# If there's no expected checksum, return success
|
||||||
local expected_checksum="$2"
|
local expected_checksum="$2"
|
||||||
|
@ -236,9 +236,9 @@ symlink_tarball_from_cache() {
|
||||||
local cached_package_filename="${RUBY_BUILD_CACHE_PATH}/$package_filename"
|
local cached_package_filename="${RUBY_BUILD_CACHE_PATH}/$package_filename"
|
||||||
local checksum="$2"
|
local checksum="$2"
|
||||||
|
|
||||||
{ verify_checksum "$cached_package_filename" "$checksum"
|
[ -e "$cached_package_filename" ] || return 1
|
||||||
ln -s "$cached_package_filename" "$package_filename"
|
verify_checksum "$cached_package_filename" "$checksum" >&4 2>&1 || return 1
|
||||||
} >&4 2>&1 || return 1
|
ln -s "$cached_package_filename" "$package_filename" >&4 2>&1 || return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
download_tarball() {
|
download_tarball() {
|
||||||
|
|
89
test/cache.bats
Normal file
89
test/cache.bats
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
#!/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
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ stub() {
|
||||||
export PATH="${BATS_TEST_DIRNAME}/stubs/${program}:$PATH"
|
export PATH="${BATS_TEST_DIRNAME}/stubs/${program}:$PATH"
|
||||||
|
|
||||||
rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run"
|
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
|
for arg in "$@"; do printf "%s\n" "$arg" >> "${TMP}/${program}-stub-plan"; done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue