49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package storage
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestMultiUsesUniqueVirtualRootNames(t *testing.T) {
|
|
a := t.TempDir()
|
|
b := t.TempDir()
|
|
m := NewMulti([]string{a, b})
|
|
if len(m.Names) != 2 || m.Names[0] == m.Names[1] {
|
|
t.Fatalf("names=%v", m.Names)
|
|
}
|
|
if _, _, ok := m.FindRoot(m.Names[0]); !ok {
|
|
t.Fatal("first root not addressable")
|
|
}
|
|
if _, _, ok := m.FindRoot(m.Names[1]); !ok {
|
|
t.Fatal("second root not addressable")
|
|
}
|
|
}
|
|
|
|
func TestMultiRenameCannotCrossRoots(t *testing.T) {
|
|
a := t.TempDir()
|
|
b := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(a, "src.txt"), []byte("src"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m := NewMulti([]string{a, b})
|
|
err := m.Rename(m.Names[0]+"/src.txt", m.Names[1]+"/dst.txt")
|
|
if err == nil {
|
|
t.Fatal("expected cross-root rename to fail")
|
|
}
|
|
if _, err := os.Stat(filepath.Join(a, "src.txt")); err != nil {
|
|
t.Fatalf("source disappeared: %v", err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(b, "dst.txt")); !os.IsNotExist(err) {
|
|
t.Fatalf("destination unexpectedly created: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestMultiRemoveCannotRemoveVirtualRoot(t *testing.T) {
|
|
m := NewMulti([]string{t.TempDir()})
|
|
if err := m.Remove(""); err == nil {
|
|
t.Fatal("expected virtual root removal to fail")
|
|
}
|
|
}
|