pyenv/plugins/python-build/test/cache.bats

92 lines
2.3 KiB
Text
Raw Normal View History

2014-01-17 07:14:30 -05:00
#!/usr/bin/env bats
load test_helper
export PYTHON_BUILD_SKIP_MIRROR=1
export PYTHON_BUILD_CACHE_PATH="$TMP/cache"
export PYTHON_BUILD_CURL_OPTS=
2014-01-17 07:14:30 -05:00
setup() {
ensure_not_found_in_path aria2c
2014-01-17 07:14:30 -05:00
mkdir "$PYTHON_BUILD_CACHE_PATH"
}
@test "packages are saved to download cache" {
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
2014-01-17 07:14:30 -05:00
install_fixture definitions/without-checksum
assert_success
assert [ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
2014-01-17 07:14:30 -05:00
unstub curl
2014-01-17 07:14:30 -05:00
}
@test "cached package without checksum" {
stub curl
2014-01-17 07:14:30 -05:00
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$PYTHON_BUILD_CACHE_PATH"
install_fixture definitions/without-checksum
assert_success
assert [ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
2014-01-17 07:14:30 -05:00
unstub curl
2014-01-17 07:14:30 -05:00
}
@test "cached package with valid checksum" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl
2014-01-17 07:14:30 -05:00
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$PYTHON_BUILD_CACHE_PATH"
install_fixture definitions/with-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
assert [ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
2014-01-17 07:14:30 -05:00
unstub curl
unstub shasum
2014-01-17 07:14:30 -05:00
}
@test "cached package with invalid checksum falls back to mirror and updates cache" {
export PYTHON_BUILD_SKIP_MIRROR=
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
2014-01-17 07:14:30 -05:00
stub shasum true "echo invalid" "echo $checksum"
stub curl "-*I* * : true" \
"-q -o * -*S* https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
2014-01-17 07:14:30 -05:00
touch "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz"
install_fixture definitions/with-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
assert [ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
assert diff -q "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" "${FIXTURE_ROOT}/package-1.0.0.tar.gz"
2014-01-17 07:14:30 -05:00
unstub curl
unstub shasum
2014-01-17 07:14:30 -05:00
}
@test "nonexistent cache directory is ignored" {
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
2014-01-17 07:14:30 -05:00
export PYTHON_BUILD_CACHE_PATH="${TMP}/nonexistent"
install_fixture definitions/without-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
refute [ -d "$PYTHON_BUILD_CACHE_PATH" ]
2014-01-17 07:14:30 -05:00
unstub curl
2014-01-17 07:14:30 -05:00
}