发布 0.1.0:通知渠道、告警规则、令牌版本与安全加固
This commit is contained in:
@@ -25,6 +25,8 @@ type fakeClient struct {
|
||||
tenancyErr error
|
||||
profile oci.AccountProfile
|
||||
profileErr error
|
||||
caps oci.AccountCapabilities
|
||||
capsErr error
|
||||
|
||||
regionSubs []oci.RegionSubscription
|
||||
regionSubsErr error
|
||||
@@ -43,6 +45,10 @@ type fakeClient struct {
|
||||
instancesErr error
|
||||
costItems []oci.CostItem
|
||||
costErr error
|
||||
instance oci.Instance
|
||||
instanceErr error
|
||||
image oci.Image
|
||||
imageErr error
|
||||
|
||||
subscribedHomeRegion string
|
||||
subscribedKey string
|
||||
@@ -55,6 +61,10 @@ func (f *fakeClient) ValidateKey(ctx context.Context, cred oci.Credentials) (oci
|
||||
return f.tenancy, f.tenancyErr
|
||||
}
|
||||
|
||||
func (f *fakeClient) GetAccountCapabilities(ctx context.Context, cred oci.Credentials, region string) (oci.AccountCapabilities, error) {
|
||||
return f.caps, f.capsErr
|
||||
}
|
||||
|
||||
func (f *fakeClient) FetchAccountProfile(ctx context.Context, cred oci.Credentials) (oci.AccountProfile, error) {
|
||||
return f.profile, f.profileErr
|
||||
}
|
||||
@@ -107,6 +117,14 @@ func (f *fakeClient) ListInstances(ctx context.Context, cred oci.Credentials, re
|
||||
return f.instances, f.instancesErr
|
||||
}
|
||||
|
||||
func (f *fakeClient) GetInstance(ctx context.Context, cred oci.Credentials, region, instanceID string) (oci.Instance, error) {
|
||||
return f.instance, f.instanceErr
|
||||
}
|
||||
|
||||
func (f *fakeClient) GetImage(ctx context.Context, cred oci.Credentials, region, imageID string) (oci.Image, error) {
|
||||
return f.image, f.imageErr
|
||||
}
|
||||
|
||||
func (f *fakeClient) SummarizeCosts(ctx context.Context, cred oci.Credentials, q oci.CostQuery) ([]oci.CostItem, error) {
|
||||
return f.costItems, f.costErr
|
||||
}
|
||||
@@ -312,6 +330,7 @@ func TestVerifyMissingConfig(t *testing.T) {
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
svc := newTestService(t, &fakeClient{tenancy: oci.TenancyInfo{Name: "t"}})
|
||||
migrateTenantDeleteModels(t, svc.db)
|
||||
cfg, err := svc.Import(context.Background(), trialImportInput())
|
||||
if err != nil {
|
||||
t.Fatalf("Import: %v", err)
|
||||
@@ -458,3 +477,39 @@ func TestListReturnsSummaries(t *testing.T) {
|
||||
t.Errorf("items[1] alias/group = %q/%q, want 生产号/empty", items[1].Alias, items[1].Group)
|
||||
}
|
||||
}
|
||||
|
||||
// TestVerifySuspendedOverridesStatus 云端暂停标记应覆盖测活结论为 suspended;
|
||||
// 能力接口失败或未标记时不改变原结论。
|
||||
func TestVerifySuspendedOverridesStatus(t *testing.T) {
|
||||
client := &fakeClient{tenancy: oci.TenancyInfo{Name: "t"}}
|
||||
svc := newTestService(t, client)
|
||||
cfg := importAliveConfig(t, svc)
|
||||
ctx := context.Background()
|
||||
|
||||
// 标记暂停:即使 ValidateKey 成功也应判 suspended
|
||||
client.caps = oci.AccountCapabilities{Suspended: true, AccountStatus: "terminated"}
|
||||
got, _, err := svc.Verify(ctx, cfg.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("Verify: %v", err)
|
||||
}
|
||||
if got.AliveStatus != model.AliveStatusSuspended {
|
||||
t.Fatalf("AliveStatus = %q, want suspended", got.AliveStatus)
|
||||
}
|
||||
if got.LastError == "" {
|
||||
t.Error("暂停时 LastError 应携带账户状态备注")
|
||||
}
|
||||
|
||||
// 解除暂停:恢复 alive
|
||||
client.caps = oci.AccountCapabilities{}
|
||||
got, _, err = svc.Verify(ctx, cfg.ID)
|
||||
if err != nil || got.AliveStatus != model.AliveStatusAlive {
|
||||
t.Fatalf("解除暂停后 = %q, %v; want alive", got.AliveStatus, err)
|
||||
}
|
||||
|
||||
// 能力接口失败:不影响测活结论
|
||||
client.capsErr = errors.New("boom")
|
||||
got, _, err = svc.Verify(ctx, cfg.ID)
|
||||
if err != nil || got.AliveStatus != model.AliveStatusAlive {
|
||||
t.Fatalf("能力接口失败后 = %q, %v; want alive", got.AliveStatus, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user