|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load test_helper |
| 4 | +export RUBY_BUILD_SKIP_MIRROR=1 |
| 5 | +export RUBY_BUILD_CACHE_PATH="$TMP/cache" |
| 6 | + |
| 7 | +setup() { |
| 8 | + mkdir "$RUBY_BUILD_CACHE_PATH" |
| 9 | +} |
| 10 | + |
| 11 | + |
| 12 | +@test "packages are saved to download cache" { |
| 13 | + stub md5 true |
| 14 | + stub curl "-*S* : cat package-1.0.0.tar.gz" |
| 15 | + |
| 16 | + install_fixture definitions/without-checksum |
| 17 | + [ "$status" -eq 0 ] |
| 18 | + [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] |
| 19 | + |
| 20 | + unstub curl |
| 21 | + unstub md5 |
| 22 | +} |
| 23 | + |
| 24 | + |
| 25 | +@test "cached package without checksum" { |
| 26 | + stub md5 true |
| 27 | + stub curl |
| 28 | + |
| 29 | + cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH" |
| 30 | + |
| 31 | + install_fixture definitions/without-checksum |
| 32 | + [ "$status" -eq 0 ] |
| 33 | + [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] |
| 34 | + |
| 35 | + unstub curl |
| 36 | + unstub md5 |
| 37 | +} |
| 38 | + |
| 39 | + |
| 40 | +@test "cached package with valid checksum" { |
| 41 | + stub md5 true "echo 83e6d7725e20166024a1eb74cde80677" |
| 42 | + stub curl |
| 43 | + |
| 44 | + cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH" |
| 45 | + |
| 46 | + install_fixture definitions/with-checksum |
| 47 | + [ "$status" -eq 0 ] |
| 48 | + [ -x "${INSTALL_ROOT}/bin/package" ] |
| 49 | + [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] |
| 50 | + |
| 51 | + unstub curl |
| 52 | + unstub md5 |
| 53 | +} |
| 54 | + |
| 55 | + |
| 56 | +@test "cached package with invalid checksum falls back to mirror and updates cache" { |
| 57 | + export RUBY_BUILD_SKIP_MIRROR= |
| 58 | + local checksum="83e6d7725e20166024a1eb74cde80677" |
| 59 | + |
| 60 | + stub md5 true "echo invalid" "echo $checksum" |
| 61 | + stub curl "-*I* : true" "-*S* http://?*/$checksum : cat package-1.0.0.tar.gz" |
| 62 | + |
| 63 | + touch "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" |
| 64 | + |
| 65 | + install_fixture definitions/with-checksum |
| 66 | + [ "$status" -eq 0 ] |
| 67 | + [ -x "${INSTALL_ROOT}/bin/package" ] |
| 68 | + [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] |
| 69 | + diff -q "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" "${FIXTURE_ROOT}/package-1.0.0.tar.gz" |
| 70 | + |
| 71 | + unstub curl |
| 72 | + unstub md5 |
| 73 | +} |
| 74 | + |
| 75 | + |
| 76 | +@test "nonexistent cache directory is ignored" { |
| 77 | + stub md5 true |
| 78 | + stub curl "-*S* : cat package-1.0.0.tar.gz" |
| 79 | + |
| 80 | + export RUBY_BUILD_CACHE_PATH="${TMP}/nonexistent" |
| 81 | + |
| 82 | + install_fixture definitions/without-checksum |
| 83 | + [ "$status" -eq 0 ] |
| 84 | + [ -x "${INSTALL_ROOT}/bin/package" ] |
| 85 | + [ ! -d "$RUBY_BUILD_CACHE_PATH" ] |
| 86 | + |
| 87 | + unstub curl |
| 88 | + unstub md5 |
| 89 | +} |
0 commit comments