返回 DeepSeek-Reasonix
rename_noreplace_windows_test.go
根目录 / internal / repair / rename_noreplace_windows_test.go
1 //go:build windows
2
3 package repair
4
5 import (
6 "os"
7 "path/filepath"
8 "testing"
9 )
10
11 func TestRenameRepairNodeNoReplaceWindowsPreservesExistingDestination(t *testing.T) {
12 dir := t.TempDir()
13 source := filepath.Join(dir, "source")
14 destination := filepath.Join(dir, "destination")
15 if err := os.WriteFile(source, []byte("source"), 0o600); err != nil {
16 t.Fatal(err)
17 }
18 if err := os.WriteFile(destination, []byte("destination"), 0o600); err != nil {
19 t.Fatal(err)
20 }
21
22 if err := renameRepairNodeNoReplace(source, destination); err == nil {
23 t.Fatal("Windows no-replace rename overwrote an existing destination")
24 }
25 for path, want := range map[string]string{source: "source", destination: "destination"} {
26 got, err := os.ReadFile(path)
27 if err != nil || string(got) != want {
28 t.Fatalf("%s = %q, %v; want %q", filepath.Base(path), got, err, want)
29 }
30 }
31 }
32
32 lines GO