Files
seaweedfs/weed/filer/filer_rename_test.go
T
Chris Lu 6f14be1138 stats: remote-mount bucket cache hit/miss metrics (#10352)
Reads of remote-backed entries now record hit or miss in
SeaweedFS_remote_cache_read_total{source,bucket,result} on the filer HTTP
path and the S3 gateway, so cache effectiveness of mounted buckets can be
graphed. Inline-content entries count as hits since they are served
locally without chunks. The filer purges the per-bucket series when the
bucket directory is deleted, so a standalone filer does not accumulate
series across bucket delete/recreate churn.
2026-07-16 16:58:45 -07:00

32 lines
957 B
Go

package filer
import (
"testing"
"github.com/seaweedfs/seaweedfs/weed/util"
)
func TestDetectBucket(t *testing.T) {
tests := []struct {
name string
fullPath string
bucketsPath string
want string
}{
{"object in bucket", "/buckets/mybucket/a/b.txt", "/buckets", "mybucket"},
{"bucket root", "/buckets/mybucket", "/buckets", "mybucket"},
{"not under buckets path", "/other/path/x", "/buckets", ""},
{"buckets path itself", "/buckets", "/buckets", ""},
{"custom buckets path", "/data/buckets/mybucket/x", "/data/buckets", "mybucket"},
{"nested object", "/buckets/b/deep/nested/key", "/buckets", "b"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := &Filer{DirBucketsPath: tt.bucketsPath}
if got := f.DetectBucket(util.FullPath(tt.fullPath)); got != tt.want {
t.Errorf("DetectBucket(%q) with buckets path %q = %q, want %q", tt.fullPath, tt.bucketsPath, got, tt.want)
}
})
}
}