improve version and mirror updating
shellcheck / shellcheck (push) Failing after 14s

This commit is contained in:
2026-11-04 07:08:44 -07:00
parent 7f37a1b9ee
commit c3ac9f49d0
10 changed files with 175 additions and 2 deletions
+47
View File
@@ -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
}