mirror of
https://github.com/rbenv/ruby-build.git
synced 2025-01-01 14:44:48 +01:00
21494ba359
Bats doesn't support both suite-wide setup (in helper) *and* file-wide
setup. Which means the existance of any file-level setup() function
overwrites any setup() function from test_helper. This can be confusing,
and (IMO) easier to simply avoid the overwriting and remove any
_implied_ suite-wide setup function from test_helper.
This turns out to not be so bad for the recently added setup function,
because the only test files that actually need aria2c removed from PATH
are those that actually invoke curl. These can be found because they are
the only test files that stub curl; half of which already had
file-specific setup() functions. So the only ones which need a
file-local setup() function added were: checksum.bats and mirror.bats
Along these lines, rbenv.bats and hooks.bats were removing aria2c from
PATH but don't actually need to. (curl isn't stubbed in these tests so
the existance of aria2c wouldn't affect the tests)
Lastly, fixed a tab/spaces whitespace mixup that was introduced by:
750c086d11
133 lines
3.5 KiB
Bash
Executable file
133 lines
3.5 KiB
Bash
Executable file
#!/usr/bin/env bats
|
|
|
|
load test_helper
|
|
export RUBY_BUILD_SKIP_MIRROR=
|
|
export RUBY_BUILD_CACHE_PATH=
|
|
export RUBY_BUILD_MIRROR_URL=http://mirror.example.com
|
|
export RUBY_BUILD_CURL_OPTS=
|
|
|
|
setup() {
|
|
ensure_not_found_in_path aria2c
|
|
}
|
|
|
|
|
|
@test "package URL without checksum bypasses mirror" {
|
|
stub shasum true
|
|
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
|
|
|
|
install_fixture definitions/without-checksum
|
|
echo "$output" >&2
|
|
|
|
assert_success
|
|
assert [ -x "${INSTALL_ROOT}/bin/package" ]
|
|
|
|
unstub curl
|
|
unstub shasum
|
|
}
|
|
|
|
|
|
@test "package URL with checksum but no shasum support bypasses mirror" {
|
|
stub shasum false
|
|
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
|
|
|
|
install_fixture definitions/with-checksum
|
|
|
|
assert_success
|
|
assert [ -x "${INSTALL_ROOT}/bin/package" ]
|
|
|
|
unstub curl
|
|
unstub shasum
|
|
}
|
|
|
|
|
|
@test "package URL with checksum hits mirror first" {
|
|
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
|
|
local mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
|
|
|
|
stub shasum true "echo $checksum"
|
|
stub curl "-*I* $mirror_url : true" \
|
|
"-q -o * -*S* $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
|
|
|
|
install_fixture definitions/with-checksum
|
|
|
|
assert_success
|
|
assert [ -x "${INSTALL_ROOT}/bin/package" ]
|
|
|
|
unstub curl
|
|
unstub shasum
|
|
}
|
|
|
|
|
|
@test "package is fetched from original URL if mirror download fails" {
|
|
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
|
|
local mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
|
|
|
|
stub shasum true "echo $checksum"
|
|
stub curl "-*I* $mirror_url : false" \
|
|
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
|
|
|
|
install_fixture definitions/with-checksum
|
|
|
|
assert_success
|
|
assert [ -x "${INSTALL_ROOT}/bin/package" ]
|
|
|
|
unstub curl
|
|
unstub shasum
|
|
}
|
|
|
|
|
|
@test "package is fetched from original URL if mirror download checksum is invalid" {
|
|
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
|
|
local mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
|
|
|
|
stub shasum true "echo invalid" "echo $checksum"
|
|
stub curl "-*I* $mirror_url : true" \
|
|
"-q -o * -*S* $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
|
|
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
|
|
|
|
install_fixture definitions/with-checksum
|
|
echo "$output" >&2
|
|
|
|
assert_success
|
|
assert [ -x "${INSTALL_ROOT}/bin/package" ]
|
|
|
|
unstub curl
|
|
unstub shasum
|
|
}
|
|
|
|
|
|
@test "default mirror URL" {
|
|
export RUBY_BUILD_MIRROR_URL=
|
|
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
|
|
|
|
stub shasum true "echo $checksum"
|
|
stub curl "-*I* : true" \
|
|
"-q -o * -*S* https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
|
|
|
|
install_fixture definitions/with-checksum
|
|
|
|
assert_success
|
|
assert [ -x "${INSTALL_ROOT}/bin/package" ]
|
|
|
|
unstub curl
|
|
unstub shasum
|
|
}
|
|
|
|
|
|
@test "package URL with ruby-lang CDN with default mirror URL will bypasses mirror" {
|
|
export RUBY_BUILD_MIRROR_URL=
|
|
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
|
|
|
|
stub shasum true "echo $checksum"
|
|
stub curl "-q -o * -*S* https://cache.ruby-lang.org/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
|
|
|
|
run_inline_definition <<DEF
|
|
install_package "package-1.0.0" "https://cache.ruby-lang.org/packages/package-1.0.0.tar.gz#ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" copy
|
|
DEF
|
|
|
|
assert_success
|
|
assert [ -x "${INSTALL_ROOT}/bin/package" ]
|
|
|
|
unstub curl
|
|
unstub shasum
|
|
}
|