#!/usr/bin/env bats # # The smoketest's own files: its scenarios run with coredesktop-dev on test # VMs (see smoketest/README.md), but what can be checked without one is here load helpers setup() { setup_fake_home } # A machine with everything HamPack installs in place, as its health checks # expect: packages and Flatpaks (stubbed), each app at its conf version with # its desktop file, graywolf's service, not1mm and hampackremove fake_installed_machine() { stub pacman 'case "$1" in -T|-Qg) exit 0 ;; esac; exit 1' stub flatpak 'exit 0' stub systemctl '[ "$*" = "is-enabled --quiet graywolf" ]' stub uv '[ "$*" = "tool list" ] && echo "not1mm v1.0"' ( source "$REPO/lib.sh" put_app() { local path path="$(expand_vars "${CONF[install]}")" mkdir -p "$(dirname "$path")" echo app > "$path" save_installed_version "${CONF[_name]}" "${CONF[version]}" mkdir -p "$HOME/.local/share/applications" if [ -n "${CONF[desktop]}" ]; then touch "$HOME/.local/share/applications/$(basename "${CONF[desktop]}")" else touch "$HOME/.local/share/applications/${CONF[_name]}.desktop" fi } parse_conf "$REPO/binaries.conf" put_app parse_conf "$REPO/compile.conf" put_app ) touch "$HOME/.local/share/applications/k6gte-not1mm.desktop" "$HOME/.local/bin/hampackremove" chmod +x "$HOME/.local/bin/hampackremove" ln -s "$REPO/radio" "$HOME/.local/bin/radio" } @test "smoketest: health passes on a machine with everything installed" { fake_installed_machine run bash "$REPO/smoketest/health" [ "$status" -eq 0 ] [[ "$output" == *"checked direwolf"* ]] [[ "$output" == *"checked paracon"* ]] [[ "$output" == *"HamPack is healthy"* ]] } @test "smoketest: health names each thing that's wrong, and fails" { fake_installed_machine stub pacman '[ "$2" != fldigi ] && [ "$1" = -T ]' stub flatpak '[ "$2" != io.github.foldynl.QLog ]' rm "$HOME/.local/bin/dump1090" "$HOME/.local/share/applications/js8call.desktop" sed -i 's/^paracon=.*/paracon=0.1/' "$HAMPACK_STATE/.installed_versions" stub systemctl 'exit 1' run bash "$REPO/smoketest/health" [ "$status" -eq 1 ] [[ "$output" == *"PROBLEM: package fldigi isn't installed"* ]] [[ "$output" == *"PROBLEM: Flatpak io.github.foldynl.QLog isn't installed"* ]] [[ "$output" == *"PROBLEM: Dump1090 isn't installed at $HOME/.local/bin/dump1090"* ]] [[ "$output" == *"PROBLEM: js8call-improved has no desktop file"* ]] [[ "$output" == *"PROBLEM: paracon is recorded at version 0.1, not 1.3.0"* ]] [[ "$output" == *"PROBLEM: graywolf's service isn't enabled"* ]] [[ "$output" == *"6 problem(s)"* ]] } @test "smoketest: health finds a binary missing a library" { fake_installed_machine printf '\177ELF' > "$HOME/.local/bin/direwolf" stub ldd 'echo " libhamlib.so.4 => not found"' run bash "$REPO/smoketest/health" [ "$status" -eq 1 ] [[ "$output" == *"PROBLEM: direwolf can't find libraries: libhamlib.so.4"* ]] } @test "smoketest: setup turns the Windows installers off for the session, now and after reboots" { stub systemctl 'exit 0' run bash "$REPO/smoketest/setup" [ "$status" -eq 0 ] grep -qx "systemctl --user set-environment HAMPACK_SKIP_WINDOWS_APPS=1" "$STUB_LOG" grep -qx HAMPACK_SKIP_WINDOWS_APPS=1 "$HOME/.config/environment.d/90-hampack-smoketest.conf" } @test "smoketest: the scenarios' helpers read compile.conf at the commit under test" { project_dir() { echo "$REPO"; } project_sha() { git -C "$REPO" rev-parse HEAD; } source "$REPO/smoketest/lib.sh" run compiled_apps [ "$output" = "$(git -C "$REPO" show HEAD:compile.conf | sed -n 's/^\[\(.*\)\]$/\1/p')" ] [[ "$output" == *Dump1090* ]] [ "$(compiled_version Dump1090)" = "$(git -C "$REPO" show HEAD:compile.conf | sed -n '/^\[Dump1090\]/,/^$/s/^version=//p')" ] [ -n "$(compiled_version direwolf)" ] [ -z "$(compiled_version nosuchapp)" ] } @test "smoketest: every scenario sets a description, image and tier, and defines scenario" { for file in "$REPO"/smoketest/scenarios/*.sh; do ( unset DESCRIPTION IMAGE TIER unset -f scenario source "$file" [ -n "$DESCRIPTION" ] || { echo "$file: no DESCRIPTION"; exit 1; } [[ "$IMAGE" == base || "$IMAGE" == installed ]] || { echo "$file: IMAGE is '$IMAGE'"; exit 1; } [[ "$TIER" == pr || "$TIER" == nightly ]] || { echo "$file: TIER is '$TIER'"; exit 1; } declare -f scenario > /dev/null || { echo "$file: no scenario function"; exit 1; } ) done } @test "smoketest: project.conf adds HamPack from the URL the README gives" { ( source "$REPO/smoketest/project.conf" [ "$NAME" = HamPack ] [ "$PARENT" = CoreDesktop ] grep -qF "sibling add ${URLS[0]}" "$REPO/README.md" ) }