30 lines
894 B
Go
30 lines
894 B
Go
package oci
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
// namespace 为租户常量:缓存命中时直接返回,不构造客户端、不发起远程调用
|
|
// (凭据为空也能取到,证明未走回源路径)。
|
|
func TestGetObjectStorageNamespaceCached(t *testing.T) {
|
|
c := NewClient()
|
|
tests := []struct {
|
|
name string
|
|
tenancy string
|
|
seed string
|
|
}{
|
|
{name: "缓存命中直接返回", tenancy: "ocid1.tenancy.oc1..aaaa", seed: "ns-a"},
|
|
{name: "不同租户各取各的", tenancy: "ocid1.tenancy.oc1..bbbb", seed: "ns-b"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
c.namespaces.Store(tt.tenancy, tt.seed)
|
|
got, err := c.GetObjectStorageNamespace(context.Background(), Credentials{TenancyOCID: tt.tenancy}, "us-ashburn-1")
|
|
if err != nil || got != tt.seed {
|
|
t.Fatalf("GetObjectStorageNamespace = %q, %v; want %q", got, err, tt.seed)
|
|
}
|
|
})
|
|
}
|
|
}
|