mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 19:09:43 +00:00
101 lines
2.3 KiB
Bash
101 lines
2.3 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
setup_file() {
|
|
PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)"
|
|
export PROJECT_ROOT
|
|
|
|
ORIGINAL_HOME="${HOME:-}"
|
|
export ORIGINAL_HOME
|
|
|
|
HOME="$(mktemp -d "${BATS_TEST_DIRNAME}/tmp-optimize-core.XXXXXX")"
|
|
export HOME
|
|
|
|
mkdir -p "$HOME"
|
|
}
|
|
|
|
teardown_file() {
|
|
rm -rf "$HOME"
|
|
if [[ -n "${ORIGINAL_HOME:-}" ]]; then
|
|
export HOME="$ORIGINAL_HOME"
|
|
fi
|
|
}
|
|
|
|
@test "needs_permissions_repair returns true when home not writable" {
|
|
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" USER="tester" bash --noprofile --norc <<'EOF'
|
|
set -euo pipefail
|
|
source "$PROJECT_ROOT/lib/optimize/tasks.sh"
|
|
stat() { echo "root"; }
|
|
export -f stat
|
|
if needs_permissions_repair; then
|
|
echo "needs"
|
|
fi
|
|
EOF
|
|
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"needs"* ]]
|
|
}
|
|
|
|
@test "has_bluetooth_hid_connected detects HID" {
|
|
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
|
|
set -euo pipefail
|
|
source "$PROJECT_ROOT/lib/optimize/tasks.sh"
|
|
system_profiler() {
|
|
cat << 'OUT'
|
|
Bluetooth:
|
|
Apple Magic Mouse:
|
|
Connected: Yes
|
|
Type: Mouse
|
|
OUT
|
|
}
|
|
export -f system_profiler
|
|
if has_bluetooth_hid_connected; then
|
|
echo "hid"
|
|
fi
|
|
EOF
|
|
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"hid"* ]]
|
|
}
|
|
|
|
@test "is_ac_power detects AC power" {
|
|
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
|
|
set -euo pipefail
|
|
source "$PROJECT_ROOT/lib/optimize/tasks.sh"
|
|
pmset() { echo "AC Power"; }
|
|
export -f pmset
|
|
if is_ac_power; then
|
|
echo "ac"
|
|
fi
|
|
EOF
|
|
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"ac"* ]]
|
|
}
|
|
|
|
@test "is_memory_pressure_high detects warning" {
|
|
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
|
|
set -euo pipefail
|
|
source "$PROJECT_ROOT/lib/optimize/tasks.sh"
|
|
memory_pressure() { echo "warning"; }
|
|
export -f memory_pressure
|
|
if is_memory_pressure_high; then
|
|
echo "high"
|
|
fi
|
|
EOF
|
|
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"high"* ]]
|
|
}
|
|
|
|
@test "opt_launch_services_rebuild handles missing lsregister" {
|
|
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" MOLE_DRY_RUN=1 bash --noprofile --norc <<'EOF'
|
|
set -euo pipefail
|
|
source "$PROJECT_ROOT/lib/core/common.sh"
|
|
source "$PROJECT_ROOT/lib/optimize/tasks.sh"
|
|
opt_launch_services_rebuild
|
|
EOF
|
|
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"LaunchServices repaired"* ]]
|
|
}
|