27 lines
873 B
Go
27 lines
873 B
Go
//go:build linux || darwin || windows
|
|
|
|
package fileops
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestRenameDirectoryNoReplacePreservesExistingDestination(t *testing.T) {
|
|
root := t.TempDir()
|
|
src := filepath.Join(root, "source")
|
|
dst := filepath.Join(root, "destination")
|
|
mustWriteFile(t, filepath.Join(src, "value.txt"), []byte("source"), 0o644)
|
|
mustWriteFile(t, filepath.Join(dst, "value.txt"), []byte("existing"), 0o644)
|
|
|
|
if err := renameDirectoryNoReplace(src, dst); err == nil {
|
|
t.Fatal("renameDirectoryNoReplace() error = nil, want existing destination failure")
|
|
}
|
|
assertFileBytes(t, filepath.Join(src, "value.txt"), []byte("source"))
|
|
assertFileBytes(t, filepath.Join(dst, "value.txt"), []byte("existing"))
|
|
if info, err := os.Stat(src); err != nil || !info.IsDir() {
|
|
t.Fatalf("source directory was not preserved: info=%v err=%v", info, err)
|
|
}
|
|
}
|