38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
//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())
|
|
}
|
|
}
|
|
}
|