@@ -16,7 +16,7 @@ func multiScopeClient() *fakeClient {
|
||||
{Key: "AMS", Name: "eu-amsterdam-1", Status: "READY"},
|
||||
},
|
||||
compartments: []oci.Compartment{
|
||||
{ID: "ocid1.compartment..a", Name: "instances", LifecycleState: "ACTIVE"},
|
||||
{ID: "ocid1.compartment..a", Name: "instances", ParentID: "ocid1.tenancy..root", LifecycleState: "ACTIVE"},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -154,6 +154,9 @@ func TestCachedCompartments(t *testing.T) {
|
||||
if len(comps) != 1 || comps[0].ID != "ocid1.compartment..a" {
|
||||
t.Errorf("comps = %+v, want 缓存中的 1 项", comps)
|
||||
}
|
||||
if comps[0].ParentID != "ocid1.tenancy..root" {
|
||||
t.Errorf("ParentID = %q, want 缓存透传 parentId", comps[0].ParentID)
|
||||
}
|
||||
|
||||
in := trialImportInput()
|
||||
in.Alias = "未开启"
|
||||
@@ -170,6 +173,32 @@ func TestCachedCompartments(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestCachedCompartmentsHealsLegacyRows 旧版缓存(未存 parentId)应实时刷新自愈并回写。
|
||||
func TestCachedCompartmentsHealsLegacyRows(t *testing.T) {
|
||||
client := multiScopeClient()
|
||||
svc := newTestService(t, client)
|
||||
cfg := importMultiConfig(t, svc)
|
||||
|
||||
// 模拟旧版残留:抹掉缓存行的 parentId
|
||||
if err := svc.db.Model(&model.CompartmentCache{}).Where("oci_config_id = ?", cfg.ID).
|
||||
Update("ParentOCID", "").Error; err != nil {
|
||||
t.Fatalf("清空 parentId: %v", err)
|
||||
}
|
||||
|
||||
comps, err := svc.CachedCompartments(context.Background(), cfg.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("CachedCompartments: %v", err)
|
||||
}
|
||||
if len(comps) != 1 || comps[0].ParentID != "ocid1.tenancy..root" {
|
||||
t.Errorf("comps = %+v, want 自愈刷新后带 parentId", comps)
|
||||
}
|
||||
var rows []model.CompartmentCache
|
||||
svc.db.Where("oci_config_id = ?", cfg.ID).Find(&rows)
|
||||
if len(rows) != 1 || rows[0].ParentOCID != "ocid1.tenancy..root" {
|
||||
t.Errorf("cache rows = %+v, want 缓存已回写 parentId", rows)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegionSubscriptionsReconcilesCache(t *testing.T) {
|
||||
client := multiScopeClient()
|
||||
svc := newTestService(t, client)
|
||||
|
||||
Reference in New Issue
Block a user