mirror of
https://github.com/tw93/Mole.git
synced 2026-03-23 22:40:08 +00:00
fix: harden CI test stability and status collector resilience
This commit is contained in:
@@ -92,10 +92,7 @@ func TestScanPathConcurrentBasic(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeletePathWithProgress(t *testing.T) {
|
||||
// Skip in CI environments where Finder may not be available.
|
||||
if os.Getenv("CI") != "" {
|
||||
t.Skip("Skipping Finder-dependent test in CI")
|
||||
}
|
||||
skipIfFinderUnavailable(t)
|
||||
|
||||
parent := t.TempDir()
|
||||
target := filepath.Join(parent, "target")
|
||||
|
||||
@@ -7,10 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func TestTrashPathWithProgress(t *testing.T) {
|
||||
// Skip in CI environments where Finder may not be available.
|
||||
if os.Getenv("CI") != "" {
|
||||
t.Skip("Skipping Finder-dependent test in CI")
|
||||
}
|
||||
skipIfFinderUnavailable(t)
|
||||
|
||||
parent := t.TempDir()
|
||||
target := filepath.Join(parent, "target")
|
||||
@@ -42,10 +39,7 @@ func TestTrashPathWithProgress(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteMultiplePathsCmdHandlesParentChild(t *testing.T) {
|
||||
// Skip in CI environments where Finder may not be available.
|
||||
if os.Getenv("CI") != "" {
|
||||
t.Skip("Skipping Finder-dependent test in CI")
|
||||
}
|
||||
skipIfFinderUnavailable(t)
|
||||
|
||||
base := t.TempDir()
|
||||
parent := filepath.Join(base, "parent")
|
||||
|
||||
44
cmd/analyze/test_helpers_test.go
Normal file
44
cmd/analyze/test_helpers_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func skipIfFinderUnavailable(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
if os.Getenv("CI") != "" {
|
||||
t.Skip("Skipping Finder-dependent test in CI")
|
||||
}
|
||||
if os.Getenv("MOLE_SKIP_FINDER_TESTS") == "1" {
|
||||
t.Skip("Skipping Finder-dependent test via MOLE_SKIP_FINDER_TESTS")
|
||||
}
|
||||
if _, err := exec.LookPath("osascript"); err != nil {
|
||||
t.Skipf("Skipping Finder-dependent test, osascript unavailable: %v", err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
cmd := exec.CommandContext(ctx, "osascript", "-e", `tell application "Finder" to get name`)
|
||||
output, err := cmd.CombinedOutput()
|
||||
text := strings.ToLower(string(output))
|
||||
if ctx.Err() == context.DeadlineExceeded {
|
||||
t.Skip("Skipping Finder-dependent test, Finder probe timed out")
|
||||
}
|
||||
if strings.Contains(text, "connection invalid") || strings.Contains(text, "can’t get application \"finder\"") || strings.Contains(text, "can't get application \"finder\"") {
|
||||
t.Skipf("Skipping Finder-dependent test, Finder probe indicates unavailable session: %s", strings.TrimSpace(string(output)))
|
||||
}
|
||||
if err != nil {
|
||||
reason := strings.TrimSpace(string(output))
|
||||
if reason == "" {
|
||||
reason = err.Error()
|
||||
}
|
||||
t.Skipf("Skipping Finder-dependent test, Finder unavailable: %s", reason)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user