#!/usr/bin/env bats load test_helper # A machine where all is well: lots of space, / on btrfs, GDM or no login # screen yet, no PulseAudio. Tests change one thing each. setup() { common_setup mkdir -p "$HOME/.local/share" ln -s "$REPO" "$HOME/.local/share/coredesktop" export FREE_KIB=$((200 * 1024 * 1024)) FSTYPE=btrfs DM="" INSTALLED="" stub df 'printf "Avail\n%s\n" "$FREE_KIB"' stub findmnt 'echo "$FSTYPE"' stub readlink '[ -n "$DM" ] && echo "/usr/lib/systemd/system/$DM"' stub pacman ' case "$1" in -Qi) [[ " $INSTALLED " == *" $2 "* ]] ;; -Qq) for p in $INSTALLED; do echo "$p"; done ;; esac' stub sudo # No terminal unless a test gives answers export COREDESKTOP_TTY="$BATS_TEST_TMPDIR/no-tty/tty" } answer() { export COREDESKTOP_TTY="$BATS_TEST_TMPDIR/answer" echo "$1" > "$COREDESKTOP_TTY" } already_installed() { mkdir -p "$HOME/.local/state/coredesktop/migrations" } @test "preflight says nothing and changes nothing when all is well" { run bash "$REPO/system/preflight.sh" [ "$status" -eq 0 ] [ -z "$output" ] not_called sudo } @test "preflight stops on too little disk space unless told to go on" { export FREE_KIB=$((30 * 1024 * 1024)) answer n run bash "$REPO/system/preflight.sh" [ "$status" -eq 1 ] [[ "$output" == *"Only 30 GB is free"* ]] answer y run bash "$REPO/system/preflight.sh" [ "$status" -eq 0 ] } @test "preflight needs less space on a machine that's already set up" { export FREE_KIB=$((30 * 1024 * 1024)) already_installed run bash "$REPO/system/preflight.sh" [ "$status" -eq 0 ] [ -z "$output" ] } @test "preflight warns once that / isn't btrfs, and goes on without a terminal" { export FSTYPE=ext4 run bash "$REPO/system/preflight.sh" [ "$status" -eq 0 ] [[ "$output" == *"/ is on ext4, not btrfs"* ]] already_installed run bash "$REPO/system/preflight.sh" [ "$status" -eq 0 ] [ -z "$output" ] } @test "preflight switches another login screen to GDM when asked to" { export DM=sddm.service answer y run bash "$REPO/system/preflight.sh" [ "$status" -eq 0 ] called sudo systemctl disable sddm.service } @test "preflight keeps another login screen, and update then leaves GDM off" { export DM=sddm.service answer n run bash "$REPO/system/preflight.sh" [ "$status" -eq 0 ] not_called sudo grep -qx "system gdm.service" "$HOME/.config/coredesktop/services-off" # Not asked again run bash "$REPO/system/preflight.sh" [ -z "$output" ] } @test "preflight changes no login screen without a terminal to ask on" { export DM=sddm.service run bash "$REPO/system/preflight.sh" [ "$status" -eq 0 ] not_called sudo } @test "preflight replaces PulseAudio and its modules with PipeWire when asked to" { export INSTALLED="pulseaudio pulseaudio-bluetooth" answer y run bash "$REPO/system/preflight.sh" [ "$status" -eq 0 ] called sudo pacman -R --noconfirm pulseaudio-bluetooth called sudo pacman -S --needed --noconfirm --ask=4 pipewire pipewire-pulse pipewire-alsa wireplumber } @test "preflight keeps PulseAudio when told to, or without a terminal" { export INSTALLED="pulseaudio" answer n run bash "$REPO/system/preflight.sh" [ "$status" -eq 0 ] [[ "$output" == *"Keeping PulseAudio."* ]] not_called sudo export COREDESKTOP_TTY="$BATS_TEST_TMPDIR/no-tty/tty" run bash "$REPO/system/preflight.sh" [ "$status" -eq 0 ] not_called sudo }