rbenv-ruby-build/test/cache.bats

89 lines
2.3 KiB
Text
Raw Permalink Normal View History

2012-11-20 06:45:00 +01:00
#!/usr/bin/env bats
load test_helper
export RUBY_BUILD_SKIP_MIRROR=1
export RUBY_BUILD_CACHE_PATH="$TMP/cache"
@test "packages are saved to download cache" {
stub curl "-q -fL -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"
2012-11-20 06:45:00 +01:00
mkdir -p "$RUBY_BUILD_CACHE_PATH"
2012-11-20 06:45:00 +01:00
install_fixture definitions/without-checksum
assert_success
2015-10-29 15:36:25 +01:00
assert [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
2012-11-20 06:45:00 +01:00
unstub curl
2012-11-20 06:45:00 +01:00
}
@test "cached package without checksum" {
stub curl
2012-11-20 06:45:00 +01:00
mkdir -p "$RUBY_BUILD_CACHE_PATH"
2012-11-20 06:45:00 +01:00
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH"
install_fixture definitions/without-checksum
assert_success
2015-10-29 15:36:25 +01:00
assert [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
2012-11-20 06:45:00 +01:00
unstub curl
2012-11-20 06:45:00 +01:00
}
@test "cached package with valid checksum" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl
2012-11-20 06:45:00 +01:00
mkdir -p "$RUBY_BUILD_CACHE_PATH"
2012-11-20 06:45:00 +01:00
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH"
install_fixture definitions/with-checksum
assert_success
2015-10-29 15:36:25 +01:00
assert [ -x "${INSTALL_ROOT}/bin/package" ]
assert [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
2012-11-20 06:45:00 +01:00
unstub curl
unstub shasum
2012-11-20 06:45:00 +01:00
}
@test "cached package with invalid checksum falls back to mirror and updates cache" {
export RUBY_BUILD_SKIP_MIRROR=
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
2012-11-20 06:45:00 +01:00
stub shasum true "echo invalid" "echo $checksum"
stub curl "-*I* : true" \
"-q -fL -o * https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4"
2012-11-20 06:45:00 +01:00
mkdir -p "$RUBY_BUILD_CACHE_PATH"
2012-11-20 06:45:00 +01:00
touch "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz"
install_fixture definitions/with-checksum
assert_success
2015-10-29 15:36:25 +01:00
assert [ -x "${INSTALL_ROOT}/bin/package" ]
assert [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
assert diff -q "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" "${FIXTURE_ROOT}/package-1.0.0.tar.gz"
2012-11-20 06:45:00 +01:00
unstub curl
unstub shasum
2012-11-20 06:45:00 +01:00
}
@test "nonexistent cache directory is ignored" {
stub curl "-q -fL -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"
2012-11-20 06:45:00 +01:00
export RUBY_BUILD_CACHE_PATH="${TMP}/nonexistent"
install_fixture definitions/without-checksum
assert_success
2015-10-29 15:36:25 +01:00
assert [ -x "${INSTALL_ROOT}/bin/package" ]
2015-10-29 15:40:32 +01:00
refute [ -d "$RUBY_BUILD_CACHE_PATH" ]
2012-11-20 06:45:00 +01:00
unstub curl
2012-11-20 06:45:00 +01:00
}