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
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ setup() {
|
||||
stub pacman 'grep "^$2 " <<< "$INSTALLED" || exit 1'
|
||||
stub checkupdates 'printf "%s" "$PENDING"; [ -n "$PENDING" ] || exit 2'
|
||||
export INSTALLED="mesa 1:26.2.6-1" PENDING=""
|
||||
# The mirror synced $SYNCED_HOURS ago (an hour by default)
|
||||
export MIRRORLIST="$BATS_TEST_TMPDIR/mirrorlist" SYNCED_HOURS=1
|
||||
echo 'Server = https://mirror.example/archlinux/$repo/os/$arch' > "$MIRRORLIST"
|
||||
stub curl 'echo "$(( $(date +%s) - SYNCED_HOURS * 3600 ))"'
|
||||
}
|
||||
|
||||
@test "version shows the kernel and Mesa, with nothing newer to install" {
|
||||
@@ -31,6 +35,7 @@ setup() {
|
||||
[[ "$output" == *"Kernel 9.9.1-arch1-1 (newer kernel installed, reboot to use it)"$'\n'* ]]
|
||||
[[ "$output" == *"Video driver Mesa 26.2.6"$'\n'* ]]
|
||||
[[ "$output" != *"is available"* ]]
|
||||
[[ "$output" != *"mirror"* ]]
|
||||
}
|
||||
|
||||
@test "version suggests update for a newer kernel and video driver" {
|
||||
@@ -68,3 +73,19 @@ setup() {
|
||||
[[ "$output" == *"Kernel 9.9.1-arch1-1"* ]]
|
||||
[[ "$output" != *"is available"* ]]
|
||||
}
|
||||
|
||||
@test "version warns when the package mirror is behind Arch" {
|
||||
export SYNCED_HOURS=73
|
||||
run bash "$CD/version"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Your package mirror (https://mirror.example/archlinux) last synced with Arch 3 days ago"* ]]
|
||||
[[ "$output" == *"Run update"* ]]
|
||||
}
|
||||
|
||||
@test "version doesn't warn about a mirror it can't reach" {
|
||||
rm "$STUB_BIN/curl"
|
||||
stub curl 'exit 7'
|
||||
run bash "$CD/version"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" != *"mirror"* ]]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user