This commit is contained in:
@@ -258,3 +258,50 @@ pacman_log() {
|
||||
run initramfs_build_failed
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
# --- mirrors ----------------------------------------------------------------
|
||||
|
||||
setup_mirrors() {
|
||||
export MIRRORLIST="$BATS_TEST_TMPDIR/mirrorlist"
|
||||
cat > "$MIRRORLIST" << 'LIST'
|
||||
## Worldwide
|
||||
#Server = https://commented.example/archlinux/$repo/os/$arch
|
||||
Server = https://first.example/archlinux/$repo/os/$arch
|
||||
Server = https://second.example/$repo/os/$arch
|
||||
LIST
|
||||
# lastsync is $SYNCED, a Unix time
|
||||
stub curl 'echo "$SYNCED"; [ -n "$SYNCED" ]'
|
||||
source "$REPO/utils.sh"
|
||||
}
|
||||
|
||||
@test "first_mirror is the first Server line that isn't commented out" {
|
||||
setup_mirrors
|
||||
[ "$(first_mirror)" = "https://first.example/archlinux" ]
|
||||
}
|
||||
|
||||
@test "mirror_age_hours reads the first mirror's lastsync" {
|
||||
setup_mirrors
|
||||
export SYNCED="$(( $(date +%s) - 30 * 3600 ))"
|
||||
run mirror_age_hours
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = 30 ]
|
||||
called curl -sf --max-time 10 https://first.example/archlinux/lastsync
|
||||
}
|
||||
|
||||
@test "mirror_age_hours fails when the mirror can't be reached or has no lastsync" {
|
||||
setup_mirrors
|
||||
export SYNCED=""
|
||||
run mirror_age_hours
|
||||
[ "$status" -ne 0 ]
|
||||
export SYNCED="<html>Not Found</html>"
|
||||
run mirror_age_hours
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
|
||||
@test "mirror_age_hours fails without a mirrorlist" {
|
||||
setup_mirrors
|
||||
rm "$MIRRORLIST"
|
||||
run mirror_age_hours
|
||||
[ "$status" -ne 0 ]
|
||||
not_called curl
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user