1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-05 00:59:41 +00:00

refactor: Consolidate and refactor test suite by removing redundant files and simplifying test execution.

This commit is contained in:
Tw93
2026-01-03 12:04:57 +08:00
parent f5a8adb97e
commit 4aef2de0fc
18 changed files with 391 additions and 546 deletions

View File

@@ -4,6 +4,9 @@ setup_file() {
PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)"
export PROJECT_ROOT
CURRENT_VERSION="$(grep '^VERSION=' "$PROJECT_ROOT/mole" | head -1 | sed 's/VERSION=\"\\(.*\\)\"/\\1/')"
export CURRENT_VERSION
ORIGINAL_HOME="${HOME:-}"
export ORIGINAL_HOME
@@ -161,3 +164,72 @@ EOF
[[ "$output" == *"MOLE_CACHE_RESET"* ]]
[[ "$output" == *"All updates completed"* ]]
}
@test "update_via_homebrew reports already on latest version" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF'
set -euo pipefail
MOLE_TEST_BREW_UPDATE_OUTPUT="Updated 0 formulae"
MOLE_TEST_BREW_UPGRADE_OUTPUT="Warning: mole 1.7.9 already installed"
MOLE_TEST_BREW_LIST_OUTPUT="mole 1.7.9"
start_inline_spinner() { :; }
stop_inline_spinner() { :; }
brew() {
case "$1" in
update) echo "$MOLE_TEST_BREW_UPDATE_OUTPUT";;
upgrade) echo "$MOLE_TEST_BREW_UPGRADE_OUTPUT";;
list) if [[ "$2" == "--versions" ]]; then echo "$MOLE_TEST_BREW_LIST_OUTPUT"; fi ;;
esac
}
export -f brew start_inline_spinner stop_inline_spinner
source "$PROJECT_ROOT/lib/core/common.sh"
update_via_homebrew "1.7.9"
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Already on latest version"* ]]
}
@test "update_mole skips download when already latest" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" CURRENT_VERSION="$CURRENT_VERSION" PATH="$HOME/fake-bin:/usr/bin:/bin" TERM="dumb" bash --noprofile --norc << 'EOF'
set -euo pipefail
curl() {
local out=""
local url=""
while [[ $# -gt 0 ]]; do
case "$1" in
-o)
out="$2"
shift 2
;;
http*://*)
url="$1"
shift
;;
*)
shift
;;
esac
done
if [[ -n "$out" ]]; then
echo "Installer executed" > "$out"
return 0
fi
if [[ "$url" == *"api.github.com"* ]]; then
echo "{\"tag_name\":\"$CURRENT_VERSION\"}"
else
echo "VERSION=\"$CURRENT_VERSION\""
fi
}
export -f curl
brew() { exit 1; }
export -f brew
"$PROJECT_ROOT/mole" update
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Already on latest version"* ]]
}