mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 17:24:45 +00:00
- Change delete confirmation from double-delete to Delete→Enter - Move files to macOS Trash instead of permanent deletion - Allow file recovery from Trash if accidentally deleted - Update UI prompts to show 'Press Enter to confirm' - Skip Finder-dependent tests in CI environments - Update SECURITY_AUDIT.md with new safety mechanisms Closes #288
88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
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")
|
|
}
|
|
|
|
parent := t.TempDir()
|
|
target := filepath.Join(parent, "target")
|
|
if err := os.MkdirAll(target, 0o755); err != nil {
|
|
t.Fatalf("create target: %v", err)
|
|
}
|
|
|
|
files := []string{
|
|
filepath.Join(target, "one.txt"),
|
|
filepath.Join(target, "two.txt"),
|
|
}
|
|
for _, f := range files {
|
|
if err := os.WriteFile(f, []byte("content"), 0o644); err != nil {
|
|
t.Fatalf("write %s: %v", f, err)
|
|
}
|
|
}
|
|
|
|
var counter int64
|
|
count, err := trashPathWithProgress(target, &counter)
|
|
if err != nil {
|
|
t.Fatalf("trashPathWithProgress returned error: %v", err)
|
|
}
|
|
if count != int64(len(files)) {
|
|
t.Fatalf("expected %d files trashed, got %d", len(files), count)
|
|
}
|
|
if _, err := os.Stat(target); !os.IsNotExist(err) {
|
|
t.Fatalf("expected target to be moved to Trash, stat err=%v", err)
|
|
}
|
|
}
|
|
|
|
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")
|
|
}
|
|
|
|
base := t.TempDir()
|
|
parent := filepath.Join(base, "parent")
|
|
child := filepath.Join(parent, "child")
|
|
|
|
// Structure: parent/fileA, parent/child/fileC.
|
|
if err := os.MkdirAll(child, 0o755); err != nil {
|
|
t.Fatalf("mkdir: %v", err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(parent, "fileA"), []byte("a"), 0o644); err != nil {
|
|
t.Fatalf("write fileA: %v", err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(child, "fileC"), []byte("c"), 0o644); err != nil {
|
|
t.Fatalf("write fileC: %v", err)
|
|
}
|
|
|
|
var counter int64
|
|
msg := deleteMultiplePathsCmd([]string{parent, child}, &counter)()
|
|
progress, ok := msg.(deleteProgressMsg)
|
|
if !ok {
|
|
t.Fatalf("expected deleteProgressMsg, got %T", msg)
|
|
}
|
|
if progress.err != nil {
|
|
t.Fatalf("unexpected error: %v", progress.err)
|
|
}
|
|
if progress.count != 2 {
|
|
t.Fatalf("expected 2 files trashed, got %d", progress.count)
|
|
}
|
|
if _, err := os.Stat(parent); !os.IsNotExist(err) {
|
|
t.Fatalf("expected parent to be moved to Trash, err=%v", err)
|
|
}
|
|
}
|
|
|
|
func TestMoveToTrashNonExistent(t *testing.T) {
|
|
err := moveToTrash("/nonexistent/path/that/does/not/exist")
|
|
if err == nil {
|
|
t.Fatal("expected error for non-existent path")
|
|
}
|
|
}
|