Empty the default KERNELS map and make tests chroot-safe
Custom kernels are now set only in the config, so the defaults suit any system. The reboot check's modules folder can be overridden with UPDATE_NOTIFY_MODULES_DIR, so the tests no longer need an installed kernel.
This commit is contained in:
+22
-17
@@ -7,27 +7,17 @@ bats_load_library bats-assert
|
||||
|
||||
SCRIPT=$BATS_TEST_DIRNAME/../update-notify
|
||||
|
||||
setup_file() {
|
||||
# A kernel release whose vmlinuz exists, so the reboot check stays quiet unless a test fakes one
|
||||
local f
|
||||
for f in /usr/lib/modules/*/vmlinuz; do
|
||||
[[ -e $f ]] || continue
|
||||
f=${f%/vmlinuz}
|
||||
export INSTALLED_KERNEL=${f##*/}
|
||||
return
|
||||
done
|
||||
echo "no /usr/lib/modules/*/vmlinuz found" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
setup() {
|
||||
export STUB_DATA=$BATS_TEST_TMPDIR/data
|
||||
export XDG_CONFIG_HOME=$BATS_TEST_TMPDIR/config
|
||||
export XDG_STATE_HOME=$BATS_TEST_TMPDIR/state
|
||||
export STUB_KERNEL=$INSTALLED_KERNEL
|
||||
# The running kernel has its vmlinuz, so the reboot check stays quiet unless a test changes STUB_KERNEL
|
||||
export STUB_KERNEL=6.1.1-test
|
||||
export UPDATE_NOTIFY_MODULES_DIR=$BATS_TEST_TMPDIR/modules
|
||||
STATE=$XDG_STATE_HOME/update-notify
|
||||
BIN=$BATS_TEST_TMPDIR/bin
|
||||
mkdir -p "$STUB_DATA" "$XDG_CONFIG_HOME/update-notify" "$BIN"
|
||||
mkdir -p "$STUB_DATA" "$XDG_CONFIG_HOME/update-notify" "$BIN" "$UPDATE_NOTIFY_MODULES_DIR/$STUB_KERNEL"
|
||||
touch "$UPDATE_NOTIFY_MODULES_DIR/$STUB_KERNEL/vmlinuz"
|
||||
# PATH holds only the stubs and the real tools the script needs, so a removed stub is a missing command
|
||||
local tool
|
||||
for tool in mkdir mv rm id timeout vercmp; do
|
||||
@@ -45,6 +35,7 @@ repo_updates() { printf '%s\n' "$@" > "$STUB_DATA/checkupdates"; }
|
||||
aur_updates() { printf '%s\n' "$@" > "$STUB_DATA/aur"; }
|
||||
installed() { printf '%s\n' "$@" > "$STUB_DATA/installed"; }
|
||||
pacnew_files() { printf '%s\n' "$@" > "$STUB_DATA/pacdiff"; }
|
||||
custom_linux() { config "KERNELS=([linux]=linux-custom)"; }
|
||||
|
||||
# Runs the script; notifications and stub calls are logged from this run only
|
||||
run_script() {
|
||||
@@ -178,7 +169,17 @@ assert_called() {
|
||||
|
||||
# --- Kernel check ---
|
||||
|
||||
@test "no kernel check by default" {
|
||||
installed "linux 6.1.1-1" "linux-custom 6.1.1-1"
|
||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
||||
run_script
|
||||
assert_success
|
||||
assert_no_notification
|
||||
assert_pending "threshold 30" "repo linux 6.1.2-1"
|
||||
}
|
||||
|
||||
@test "stock kernel update notifies the rebuild below the threshold" {
|
||||
custom_linux
|
||||
installed "linux 6.1.1-1" "linux-custom 6.1.1-1"
|
||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
||||
run_script
|
||||
@@ -189,6 +190,7 @@ assert_called() {
|
||||
|
||||
@test "kernel rebuild joins the counts over the threshold" {
|
||||
config THRESHOLD=1
|
||||
custom_linux
|
||||
installed "linux 6.1.2-1" "linux-custom 6.1.1-1"
|
||||
run_script 0
|
||||
assert_success
|
||||
@@ -196,6 +198,7 @@ assert_called() {
|
||||
}
|
||||
|
||||
@test "kernel check ignores pkgrel" {
|
||||
custom_linux
|
||||
installed "linux 6.1.1-1" "linux-custom 6.1.1-1"
|
||||
repo_updates "linux 6.1.1-1 -> 6.1.1-2"
|
||||
run_script
|
||||
@@ -204,6 +207,7 @@ assert_called() {
|
||||
}
|
||||
|
||||
@test "custom kernel already built into the repo isn't flagged" {
|
||||
custom_linux
|
||||
installed "linux 6.1.1-1" "linux-custom 6.1.1-1"
|
||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1" "linux-custom 6.1.1-1 -> 6.1.2-1"
|
||||
run_script
|
||||
@@ -212,6 +216,7 @@ assert_called() {
|
||||
}
|
||||
|
||||
@test "kernels without a custom build installed are skipped" {
|
||||
custom_linux
|
||||
installed "linux 6.1.1-1"
|
||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
||||
run_script
|
||||
@@ -221,8 +226,7 @@ assert_called() {
|
||||
|
||||
@test "custom kernel map comes from the config" {
|
||||
config "KERNELS=([linux-hardened]=linux-hardened-mine)"
|
||||
installed "linux 6.1.1-1" "linux-custom 6.1.1-1" "linux-hardened 6.1.2-1" "linux-hardened-mine 6.1.1-1"
|
||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
||||
installed "linux-hardened 6.1.2-1" "linux-hardened-mine 6.1.1-1"
|
||||
run_script
|
||||
assert_success
|
||||
assert_notification "Kernel update available" "Rebuild linux-hardened-mine (linux-hardened 6.1.2-1)"
|
||||
@@ -398,6 +402,7 @@ assert_called() {
|
||||
@test "no reminders below the threshold" {
|
||||
enable_stub git-monitor
|
||||
enable_stub fwupdmgr
|
||||
custom_linux
|
||||
installed "linux 6.1.2-1" "linux-custom 6.1.1-1"
|
||||
run_script
|
||||
assert_notification "Kernel update available" "Rebuild linux-custom (linux 6.1.2-1)"
|
||||
|
||||
Reference in New Issue
Block a user