127 lines
3.8 KiB
Bash
127 lines
3.8 KiB
Bash
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
source "$(dirname "$0")/base-test.sh"
|
|
|
|
test_tmp=$(mktemp -d)
|
|
trap 'rm -rf "$test_tmp"' EXIT
|
|
|
|
stub_bin="$test_tmp/bin"
|
|
mkdir -p "$stub_bin"
|
|
|
|
cat >"$stub_bin/checkupdates" <<'SH'
|
|
#!/bin/bash
|
|
case "${TEST_CHECKUPDATES:-updates}" in
|
|
updates)
|
|
printf 'linux 6.1-1 -> 6.1-2\nomarchy 4.0.0-1 -> 4.0.1-1\nomarchy-settings 4.0.0-1 -> 4.0.1-1\nomarchy-dev 4.1.0-1 -> 4.1.1-1\nomarchy-settings-dev 4.1.0-1 -> 4.1.1-1\n'
|
|
exit 0
|
|
;;
|
|
none)
|
|
exit 2
|
|
;;
|
|
fail)
|
|
echo "check failed" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
SH
|
|
chmod +x "$stub_bin/checkupdates"
|
|
|
|
cat >"$stub_bin/pacman" <<'SH'
|
|
#!/bin/bash
|
|
case "$1" in
|
|
-Qq)
|
|
case "${TEST_INSTALLED_PACKAGE:-omarchy}" in
|
|
omarchy)
|
|
[[ $2 == "omarchy" ]]; exit $?
|
|
;;
|
|
omarchy-dev)
|
|
[[ $2 == "omarchy-dev" ]]; exit $?
|
|
;;
|
|
both)
|
|
[[ $2 == "omarchy" || $2 == "omarchy-dev" ]]; exit $?
|
|
;;
|
|
none)
|
|
exit 1
|
|
;;
|
|
esac
|
|
;;
|
|
esac
|
|
exit 0
|
|
SH
|
|
chmod +x "$stub_bin/pacman"
|
|
|
|
run_checker() {
|
|
PATH="$stub_bin:$PATH" "$ROOT/bin/omarchy-update-available"
|
|
}
|
|
|
|
capture_checker() {
|
|
local stdout_file="$1"
|
|
local stderr_file="$2"
|
|
shift 2
|
|
|
|
set +e
|
|
(
|
|
export "$@"
|
|
run_checker
|
|
) >"$stdout_file" 2>"$stderr_file"
|
|
local status=$?
|
|
set -e
|
|
return "$status"
|
|
}
|
|
|
|
stdout="$test_tmp/stdout"
|
|
stderr="$test_tmp/stderr"
|
|
|
|
if capture_checker "$stdout" "$stderr" TEST_CHECKUPDATES=updates TEST_INSTALLED_PACKAGE=omarchy; then
|
|
status=0
|
|
else
|
|
status=$?
|
|
fi
|
|
[[ $status -eq 0 ]] || fail "update checker exits successfully when omarchy update is available"
|
|
grep -q '^omarchy ' "$stdout" || fail "update checker prints omarchy updates"
|
|
! grep -q '^omarchy-settings ' "$stdout" || fail "update checker ignores omarchy-settings updates"
|
|
! grep -q '^linux ' "$stdout" || fail "update checker ignores non-Omarchy package updates"
|
|
! grep -q '^omarchy-dev ' "$stdout" || fail "update checker ignores omarchy-dev when omarchy is installed"
|
|
pass "update checker detects installed omarchy package updates"
|
|
|
|
if capture_checker "$stdout" "$stderr" TEST_CHECKUPDATES=updates TEST_INSTALLED_PACKAGE=omarchy-dev; then
|
|
status=0
|
|
else
|
|
status=$?
|
|
fi
|
|
[[ $status -eq 0 ]] || fail "update checker exits successfully when omarchy-dev update is available"
|
|
grep -q '^omarchy-dev ' "$stdout" || fail "update checker prints omarchy-dev updates"
|
|
! grep -q '^omarchy-settings-dev ' "$stdout" || fail "update checker ignores omarchy-settings-dev updates"
|
|
! grep -q '^omarchy ' "$stdout" || fail "update checker ignores omarchy when omarchy-dev is installed"
|
|
pass "update checker detects installed omarchy-dev package updates"
|
|
|
|
if capture_checker "$stdout" "$stderr" TEST_CHECKUPDATES=updates TEST_INSTALLED_PACKAGE=both; then
|
|
status=0
|
|
else
|
|
status=$?
|
|
fi
|
|
[[ $status -eq 0 ]] || fail "update checker prefers omarchy-dev when both packages are installed"
|
|
grep -q '^omarchy-dev ' "$stdout" || fail "update checker prints omarchy-dev when both packages are installed"
|
|
! grep -q '^omarchy ' "$stdout" || fail "update checker ignores omarchy when omarchy-dev is installed"
|
|
pass "update checker prefers omarchy-dev over omarchy"
|
|
|
|
if capture_checker "$stdout" "$stderr" TEST_CHECKUPDATES=updates TEST_INSTALLED_PACKAGE=none; then
|
|
status=0
|
|
else
|
|
status=$?
|
|
fi
|
|
[[ $status -eq 1 ]] || fail "update checker exits non-zero when no Omarchy package is installed"
|
|
[[ ! -s $stderr ]] || fail "update checker is quiet when no Omarchy package is installed"
|
|
pass "update checker ignores systems without omarchy or omarchy-dev installed"
|
|
|
|
if capture_checker "$stdout" "$stderr" TEST_CHECKUPDATES=none TEST_INSTALLED_PACKAGE=omarchy; then
|
|
status=0
|
|
else
|
|
status=$?
|
|
fi
|
|
[[ $status -eq 1 ]] || fail "update checker exits non-zero when no updates are available"
|
|
grep -q '^Omarchy is up to date$' "$stdout" || fail "update checker prints up-to-date message"
|
|
pass "update checker reports up-to-date Omarchy packages"
|