Files
coredesktop/tests/test_helper.bash
T
davidandClaude Opus 5.5 1e2581dcc5
shellcheck / shellcheck (push) Successful in 48s
Keep the running kernel's modules after a kernel upgrade
install.sh failed whenever its upgrade replaced the kernel (Arch installed
a few days earlier): pacman deletes the running kernel's modules, so Docker
and then the firewall couldn't load theirs. The smoketest found it.

kernel-modules-hook keeps them until the next reboot, and its cleanup
service removes them after. install.sh installs it with archlinux-keyring,
in a transaction of its own so its hooks run for the upgrade; packages.conf
lists it and the service, so update adds them to existing machines.

With the modules kept, a missing modules folder no longer means a newer
kernel was installed, so newer_kernel_installed (utils.sh) also counts a
folder no package owns, and the reboot check, version and finish-install
use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 18:41:50 -07:00

62 lines
1.8 KiB
Bash

#!/bin/bash
# Shared setup for the bats tests. Each test gets its own HOME and a bin dir at
# the front of PATH where it can put fake versions of pacman, yay, sudo, etc.
# Used by the .bats files that load this one
# shellcheck disable=SC2034
REPO="$(cd "$BATS_TEST_DIRNAME/.." && pwd)"
common_setup() {
export HOME="$BATS_TEST_TMPDIR/home"
export STUB_BIN="$BATS_TEST_TMPDIR/bin"
export STUB_LOG="$BATS_TEST_TMPDIR/stub.log"
mkdir -p "$HOME" "$STUB_BIN"
: > "$STUB_LOG"
export PATH="$STUB_BIN:$PATH"
unset COREDESKTOP
# Set when the tests run inside a smoketest (a pre-push hook's checks, say),
# where they would point the smoketest tests at the real VM
unset VM_GIT_SSH VM_GIT_URL SMOKETEST_REPO SMOKETEST_RESULTS SMOKETEST_SHARED \
SMOKETEST_REF SMOKETEST_VM_DIR SMOKETEST_CHAIN_FILE IMAGE_REF VARIANT
}
# A test file that needs more setup defines its own setup that calls this first
setup() {
common_setup
}
# stub NAME [BODY]: put a fake NAME on PATH that appends "NAME args..." to
# $STUB_LOG and then runs BODY, a bash snippet that sees the args as "$@"
stub() {
local name="$1" body="${2:-}"
cat > "$STUB_BIN/$name" << EOF
#!/bin/bash
echo "$name \$*" >> "\$STUB_LOG"
$body
EOF
chmod +x "$STUB_BIN/$name"
}
# called NAME ARGS...: true if the stub log has exactly the line "NAME ARGS..."
called() {
grep -qxF "$*" "$STUB_LOG"
}
# not_called NAME: true if the stub NAME never ran
not_called() {
! grep -q "^$1 " "$STUB_LOG"
}
# uncalled NAME ARGS...: the opposite of called. (A bare "! called ..." would
# not fail the test: bats, like set -e, ignores the status of a ! command.)
uncalled() {
! called "$@"
}
# refute COMMAND...: true if COMMAND fails. Use it instead of "! COMMAND",
# which doesn't fail a test (see uncalled).
refute() {
! "$@"
}