Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tencentcloud/resource_tc_cbs_disk_backup_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
package tencentcloud

import (
"context"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
cbs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs/v20170312"
)

func init() {
// go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_cbs_disk_backup
resource.AddTestSweepers("tencentcloud_cbs_disk_backup", &resource.Sweeper{
Name: "tencentcloud_cbs_disk_backup",
F: func(r string) error {
logId := getLogId(contextNil)
cli, _ := sharedClientForRegion(r)
request := cbs.NewDescribeDiskBackupsRequest()
resp, err := cli.(*TencentCloudClient).apiV3Conn.UseCbsClient().DescribeDiskBackups(request)
if err != nil {
return err
}
diskBuckups := resp.Response.DiskBackupSet
for _, diskBuckup := range diskBuckups {
created, err := time.Parse("2006-01-02 15:04:05", *diskBuckup.CreateTime)
if err != nil {
created = time.Now()
}
name := *diskBuckup.DiskBackupName
if isResourcePersist(name, &created) {
continue
}
buckupId := *diskBuckup.DiskBackupId
client := cli.(*TencentCloudClient).apiV3Conn
ctx := context.WithValue(context.TODO(), logIdKey, logId)
service := CbsService{client}
err = service.DeleteCbsDiskBackupById(ctx, buckupId)
if err != nil {
continue
}
}

return nil
},
})
}

func TestAccTencentCloudCbsDiskBackupResource_basic(t *testing.T) {
t.Parallel()

Expand Down