Update active dev checkout with system
This commit is contained in:
@@ -8,6 +8,7 @@ test_tmp=$(mktemp -d)
|
||||
trap 'rm -rf "$test_tmp"' EXIT
|
||||
|
||||
stub_bin="$test_tmp/bin"
|
||||
git_log="$test_tmp/git.log"
|
||||
mkdir -p "$stub_bin"
|
||||
|
||||
cat >"$stub_bin/checkupdates" <<'SH'
|
||||
@@ -52,8 +53,48 @@ exit 0
|
||||
SH
|
||||
chmod +x "$stub_bin/pacman"
|
||||
|
||||
cat >"$stub_bin/git" <<'SH'
|
||||
#!/bin/bash
|
||||
|
||||
printf '%s\n' "$*" >>"$TEST_GIT_LOG"
|
||||
|
||||
[[ $1 == "-C" ]] || exit 1
|
||||
shift 2
|
||||
|
||||
case "$1" in
|
||||
fetch)
|
||||
[[ ${TEST_GIT_FETCH:-ok} == "ok" ]]
|
||||
;;
|
||||
rev-parse)
|
||||
case "$2" in
|
||||
--is-inside-work-tree)
|
||||
[[ ${TEST_GIT_CHECKOUT:-yes} == "yes" ]] || exit 1
|
||||
echo true
|
||||
;;
|
||||
--abbrev-ref)
|
||||
[[ ${TEST_GIT_UPSTREAM:-origin/quattro} != "none" ]] || exit 1
|
||||
echo "${TEST_GIT_UPSTREAM:-origin/quattro}"
|
||||
;;
|
||||
*)
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
rev-list)
|
||||
echo "${TEST_GIT_BEHIND:-0}"
|
||||
;;
|
||||
*)
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
SH
|
||||
chmod +x "$stub_bin/git"
|
||||
|
||||
run_checker() {
|
||||
PATH="$stub_bin:$PATH" "$ROOT/bin/omarchy-update-available"
|
||||
OMARCHY_PATH="${TEST_OMARCHY_PATH:-/usr/share/omarchy}" \
|
||||
TEST_GIT_LOG="$git_log" \
|
||||
PATH="$stub_bin:$PATH" \
|
||||
"$ROOT/bin/omarchy-update-available"
|
||||
}
|
||||
|
||||
capture_checker() {
|
||||
@@ -124,3 +165,49 @@ 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"
|
||||
|
||||
: >"$git_log"
|
||||
if capture_checker "$stdout" "$stderr" \
|
||||
TEST_CHECKUPDATES=none \
|
||||
TEST_INSTALLED_PACKAGE=none \
|
||||
TEST_OMARCHY_PATH="$test_tmp/checkout" \
|
||||
TEST_GIT_BEHIND=2; then
|
||||
status=0
|
||||
else
|
||||
status=$?
|
||||
fi
|
||||
[[ $status -eq 0 ]] || fail "update checker exits successfully when dev commits are available"
|
||||
grep -Fx 'omarchy-dev-checkout 2 new commits on origin/quattro' "$stdout" >/dev/null ||
|
||||
fail "update checker reports available dev commits" "$(cat "$stdout")"
|
||||
grep -Fx -- "-C $test_tmp/checkout fetch --quiet" "$git_log" >/dev/null ||
|
||||
fail "update checker fetches the dev checkout upstream" "$(cat "$git_log")"
|
||||
pass "update checker detects new commits in the dev checkout"
|
||||
|
||||
if capture_checker "$stdout" "$stderr" \
|
||||
TEST_CHECKUPDATES=none \
|
||||
TEST_INSTALLED_PACKAGE=none \
|
||||
TEST_OMARCHY_PATH="$test_tmp/checkout" \
|
||||
TEST_GIT_BEHIND=0; then
|
||||
status=0
|
||||
else
|
||||
status=$?
|
||||
fi
|
||||
[[ $status -eq 1 ]] || fail "update checker exits non-zero when the dev checkout is current"
|
||||
grep -q '^Omarchy is up to date$' "$stdout" || fail "update checker reports a current dev checkout"
|
||||
pass "update checker ignores a current dev checkout"
|
||||
|
||||
if capture_checker "$stdout" "$stderr" \
|
||||
TEST_CHECKUPDATES=none \
|
||||
TEST_INSTALLED_PACKAGE=none \
|
||||
TEST_OMARCHY_PATH="$test_tmp/checkout" \
|
||||
TEST_GIT_BEHIND=1 \
|
||||
TEST_GIT_FETCH=fail; then
|
||||
status=0
|
||||
else
|
||||
status=$?
|
||||
fi
|
||||
[[ $status -eq 0 ]] || fail "update checker uses cached upstream state when fetch fails"
|
||||
grep -Fx 'omarchy-dev-checkout 1 new commit on origin/quattro' "$stdout" >/dev/null ||
|
||||
fail "update checker reports cached dev commits after a fetch failure" "$(cat "$stdout")"
|
||||
[[ ! -s $stderr ]] || fail "update checker keeps dev fetch failures quiet" "$(cat "$stderr")"
|
||||
pass "update checker uses cached dev state when fetching is unavailable"
|
||||
|
||||
Reference in New Issue
Block a user