package dirusage import ( "testing" "github.com/seaweedfs/seaweedfs/weed/util" ) func TestRootsOfAPath(t *testing.T) { for _, buckets := range []string{"/buckets", "/buckets/", ""} { roots := NewRoots(buckets) for path, want := range map[util.FullPath]util.FullPath{ "/buckets/b": "/buckets/b", "/buckets/b/x/y": "/buckets/b", "/home/u/f": "/home", "/topics/.system": "/topics", "/topics/.system/log/2026-12-03": "", "/etc/seaweedfs/dir_usage/1/top/x": "", "/buckets": "", "/": "", } { root, ok := roots.RootOf(path) if !ok { root = "" } if root != want { t.Errorf("buckets folder %q: %s counts toward %q, want %q", buckets, path, root, want) } } } nested := NewRoots("/tenant/buckets/") if root, ok := nested.RootOf("/tenant/buckets/b/f"); !ok || root != "/tenant/buckets/b" { t.Errorf("/tenant/buckets/b/f counts toward %q, %v", root, ok) } if _, ok := nested.RootOf("/tenant/other"); ok { t.Errorf("what holds the buckets folder counts") } }