Support atomic directory promotion across platforms
This commit is contained in:
37
internal/fileops/directory_unsupported_test.go
Normal file
37
internal/fileops/directory_unsupported_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
//go:build !linux && !darwin && !windows
|
||||
|
||||
package fileops
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPromoteDirectoryFailsBeforeCreatingTemporaryTree(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
src := filepath.Join(root, "source")
|
||||
dst := filepath.Join(root, "destination")
|
||||
if err := os.Mkdir(src, 0o755); err != nil {
|
||||
t.Fatalf("Mkdir(source) error = %v", err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(src, "value.txt"), []byte("source"), 0o644); err != nil {
|
||||
t.Fatalf("WriteFile(source) error = %v", err)
|
||||
}
|
||||
|
||||
err := PromoteDirectory(src, dst)
|
||||
if !errors.Is(err, ErrAtomicDirectoryPromotionUnsupported) {
|
||||
t.Fatalf("PromoteDirectory() error = %v, want unsupported capability", err)
|
||||
}
|
||||
entries, readErr := os.ReadDir(root)
|
||||
if readErr != nil {
|
||||
t.Fatalf("ReadDir(root) error = %v", readErr)
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if entry.Name() == filepath.Base(dst) || strings.HasPrefix(entry.Name(), ".destination.tmp-") {
|
||||
t.Fatalf("unsupported promotion created %q", entry.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user