@@ -3,13 +3,56 @@ package tencentcloud
33import (
44 "context"
55 "fmt"
6+ "strings"
67 "testing"
78
89 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
910 "github.com/hashicorp/terraform-plugin-sdk/terraform"
1011)
1112
12- func TestAccTencentCloudDcdbHourdbInstance_basic (t * testing.T ) {
13+ func init () {
14+ resource .AddTestSweepers ("tencentcloud_dcdb_hourdb_instance" , & resource.Sweeper {
15+ Name : "tencentcloud_dcdb_hourdb_instance" ,
16+ F : testSweepDCDBHourdbInstance ,
17+ })
18+ }
19+
20+ // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_dcdb_hourdb_instance
21+ func testSweepDCDBHourdbInstance (r string ) error {
22+ logId := getLogId (contextNil )
23+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
24+ cli , _ := sharedClientForRegion (r )
25+ dcdbService := DcdbService {client : cli .(* TencentCloudClient ).apiV3Conn }
26+
27+ instances , err := dcdbService .DescribeDcdbInstancesByFilter (ctx , nil )
28+ if err != nil {
29+ return err
30+ }
31+ if instances == nil {
32+ return fmt .Errorf ("dcdb hourdb instance not exists." )
33+ }
34+
35+ for _ , v := range instances {
36+ delId := * v .InstanceId
37+ delName := * v .InstanceName
38+
39+ if strings .HasPrefix (delName , "test_dcdc_" ) {
40+ err := resource .Retry (readRetryTimeout , func () * resource.RetryError {
41+ err := dcdbService .DeleteDcdbHourdbInstanceById (ctx , delId )
42+ if err != nil {
43+ return retryError (err )
44+ }
45+ return nil
46+ })
47+ if err != nil {
48+ return fmt .Errorf ("[ERROR] delete dcdb hourdb instance %s failed! reason:[%s]" , delId , err .Error ())
49+ }
50+ }
51+ }
52+ return nil
53+ }
54+
55+ func TestAccTencentCloudDCDBHourdbInstance_basic (t * testing.T ) {
1356 t .Parallel ()
1457
1558 resource .Test (t , resource.TestCase {
0 commit comments