Files
seaweedfs/weed/s3api/s3tables/handler_bucket_get_lookups_test.go
T
Nguyễn Lộc PhúcandClaude Opus 5.5 cf3eda7e57 perf(s3vectors): read the bucket once per authorization (#13427)
s3vectors: read the bucket once per authorization

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 23:54:04 -08:00

39 lines
1.2 KiB
Go

package s3tables
import (
"net/http"
"testing"
)
// GetTableBucket decides on the bucket entry's metadata, policy and tags, all
// returned by one lookup of the entry, yet fetched each attribute with a
// lookup of its own: two lookups, three under a policy.
func TestGetTableBucketLooksUpTheBucketOnce(t *testing.T) {
for _, withPolicy := range []bool{false, true} {
name := "no policy"
if withPolicy {
name = "policy"
}
t.Run(name, func(t *testing.T) {
fs, m := startEmptyBucket(t)
if withPolicy {
requireOK(t, m, fs, "PutTableBucketPolicy", &PutTableBucketPolicyRequest{TableBucketARN: mustBucketARN(t),
ResourcePolicy: `{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":"*","Action":"s3tables:*","Resource":"*"}]}`})
}
lookups := 0
fs.OnLookup = func(dir, name string) {
if dir == TablesPath && name == renameTestBucket {
lookups++
}
}
defer func() { fs.OnLookup = nil }()
if code, resp := runHandler(t, m, fs.Client, "GetTableBucket", &GetTableBucketRequest{TableBucketARN: mustBucketARN(t)}); code != http.StatusOK {
t.Fatalf("GetTableBucket = %d %+v", code, resp)
}
if lookups != 1 {
t.Errorf("GetTableBucket looked up the bucket %d times, want 1", lookups)
}
})
}
}