test: lock down multi-root storage isolation
This commit is contained in:
@@ -6,36 +6,43 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewMultiKeepsDuplicateBasenames(t *testing.T) {
|
func TestMultiUsesUniqueVirtualRootNames(t *testing.T) {
|
||||||
root := t.TempDir()
|
a := t.TempDir()
|
||||||
first := filepath.Join(root, "same")
|
b := t.TempDir()
|
||||||
second := filepath.Join(root, "other", "same")
|
m := NewMulti([]string{a, b})
|
||||||
if err := os.MkdirAll(first, 0o755); err != nil {
|
if len(m.Names) != 2 || m.Names[0] == m.Names[1] {
|
||||||
t.Fatal(err)
|
t.Fatalf("names=%v", m.Names)
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(second, 0o755); err != nil {
|
if _, _, ok := m.FindRoot(m.Names[0]); !ok {
|
||||||
t.Fatal(err)
|
t.Fatal("first root not addressable")
|
||||||
}
|
}
|
||||||
m := NewMulti([]string{first, second})
|
if _, _, ok := m.FindRoot(m.Names[1]); !ok {
|
||||||
if len(m.Roots) != 2 || len(m.Names) != 2 {
|
t.Fatal("second root not addressable")
|
||||||
t.Fatalf("duplicate basename dropped: roots=%d names=%v", len(m.Roots), m.Names)
|
|
||||||
}
|
|
||||||
if m.Names[0] != "same" || m.Names[1] != "same-2" {
|
|
||||||
t.Fatalf("unexpected virtual names: %v", m.Names)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiRejectsMutationOfVirtualRoot(t *testing.T) {
|
func TestMultiRenameCannotCrossRoots(t *testing.T) {
|
||||||
root1 := t.TempDir()
|
a := t.TempDir()
|
||||||
root2 := t.TempDir()
|
b := t.TempDir()
|
||||||
m := NewMulti([]string{root1, root2})
|
if err := os.WriteFile(filepath.Join(a, "src.txt"), []byte("src"), 0o644); err != nil {
|
||||||
if err := m.Remove(m.Names[0]); err == nil {
|
t.Fatal(err)
|
||||||
t.Fatal("expected virtual root removal to be rejected")
|
|
||||||
}
|
}
|
||||||
if _, err := m.Create(m.Names[0]); err == nil {
|
m := NewMulti([]string{a, b})
|
||||||
t.Fatal("expected virtual root creation to be rejected")
|
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 := m.Rename(m.Names[0], m.Names[1]); err == nil {
|
if _, err := os.Stat(filepath.Join(a, "src.txt")); err != nil {
|
||||||
t.Fatal("expected virtual root rename to be rejected")
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user