Files
coredesktop/tests/version.bats
T
david 448c8b43f1
shellcheck / shellcheck (push) Failing after 17s
fix agent networking
2026-11-02 08:57:45 -07:00

71 lines
2.5 KiB
Bash

#!/usr/bin/env bats
load test_helper
# version runs from a fake checkout with fake git, uname, pacman and
# checkupdates. The running kernel's modules never exist here, so the kernel
# line always also says a newer one is installed.
setup() {
common_setup
CD="$HOME/.local/share/coredesktop"
mkdir -p "$CD"
cp "$REPO/version" "$REPO/utils.sh" "$CD/"
stub git 'case "$3" in
rev-parse) exit 0 ;;
log) echo "2026.10.31 (6bc4fdc)" ;;
fetch) exit 1 ;;
esac'
stub uname 'echo "${KERNEL:-9.9.1-arch1-1}"'
# pacman -Q <package>: the versions in $INSTALLED, "name version" per line
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=""
}
@test "version shows the kernel and Mesa, with nothing newer to install" {
run bash "$CD/version"
[ "$status" -eq 0 ]
[[ "$output" == *"CoreDesktop 2026.10.31 (6bc4fdc)"* ]]
[[ "$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"* ]]
}
@test "version suggests update for a newer kernel and video driver" {
export PENDING=$'linux 9.9.1.arch1-1 -> 9.9.2.arch1-1\nmesa 1:26.2.6-1 -> 1:26.3.0-1\n'
run bash "$CD/version"
[ "$status" -eq 0 ]
[[ "$output" == *"Kernel 9.9.1-arch1-1"*", 9.9.2 is available (run update)"* ]]
[[ "$output" == *"Video driver Mesa 26.2.6, 26.3.0 is available (run update)"* ]]
}
@test "version shows NVIDIA's driver over Mesa, and ignores a rebuild of the same version" {
export INSTALLED=$'mesa 1:26.2.6-1\nnvidia-utils 615.78.08-1'
export PENDING=$'nvidia-utils 615.78.08-1 -> 615.78.08-2\n'
run bash "$CD/version"
[ "$status" -eq 0 ]
[[ "$output" == *"Video driver NVIDIA 615.78.08"$'\n'* ]]
[[ "$output" != *"is available"* ]]
}
@test "version checks the kernel package that's running, e.g. linux-lts" {
export KERNEL=6.12.50-1-lts
export PENDING=$'linux 9.9.1.arch1-1 -> 9.9.2.arch1-1\nlinux-lts 6.12.50-1 -> 6.12.51-1\n'
run bash "$CD/version"
[ "$status" -eq 0 ]
[[ "$output" == *"6.12.51 is available"* ]]
[[ "$output" != *"9.9.2"* ]]
}
@test "version leaves out what's available when it can't check" {
rm "$STUB_BIN/checkupdates"
stub checkupdates 'exit 1'
export PENDING=$'linux 9.9.1.arch1-1 -> 9.9.2.arch1-1\n'
run bash "$CD/version"
[ "$status" -eq 0 ]
[[ "$output" == *"Kernel 9.9.1-arch1-1"* ]]
[[ "$output" != *"is available"* ]]
}