@@ -3,12 +3,52 @@ 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
13+ func init () {
14+ resource .AddTestSweepers ("tencentcloud_cynosdb" , & resource.Sweeper {
15+ Name : "tencentcloud_cynosdb" ,
16+ F : func (r string ) error {
17+ logId := getLogId (contextNil )
18+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
19+ cli , _ := sharedClientForRegion (r )
20+ client := cli .(* TencentCloudClient ).apiV3Conn
21+ service := CynosdbService {client : client }
22+
23+ instances , err := service .DescribeClusters (ctx , nil )
24+
25+ if err != nil {
26+ return err
27+ }
28+
29+ for _ , v := range instances {
30+ id := * v .ClusterId
31+ name := * v .ClusterName
32+ status := * v .Status
33+ if status != "running" {
34+ continue
35+ }
36+ if ! strings .HasPrefix (name , "tf-cynosdb" ) {
37+ continue
38+ }
39+ _ , err := service .IsolateCluster (ctx , id )
40+ if err != nil {
41+ continue
42+ }
43+ if err = service .OfflineCluster (ctx , id ); err != nil {
44+ continue
45+ }
46+ }
47+ return nil
48+ },
49+ })
50+ }
51+
1252func TestAccTencentCloudCynosdbClusterResource (t * testing.T ) {
1353 t .Parallel ()
1454 resource .Test (t , resource.TestCase {
@@ -44,7 +84,7 @@ func TestAccTencentCloudCynosdbClusterResource(t *testing.T) {
4484 resource .TestCheckResourceAttrSet ("tencentcloud_cynosdb_cluster.foo" , "instance_status" ),
4585 resource .TestCheckResourceAttrSet ("tencentcloud_cynosdb_cluster.foo" , "instance_storage_size" ),
4686 resource .TestCheckResourceAttrSet ("tencentcloud_cynosdb_cluster.foo" , "instance_id" ),
47- resource .TestCheckResourceAttrSet ("tencentcloud_cynosdb_cluster.foo" , "charset" ),
87+ resource .TestCheckResourceAttr ("tencentcloud_cynosdb_cluster.foo" , "charset" , "utf8 " ),
4888 resource .TestCheckResourceAttrSet ("tencentcloud_cynosdb_cluster.foo" , "cluster_status" ),
4989 resource .TestCheckResourceAttrSet ("tencentcloud_cynosdb_cluster.foo" , "create_time" ),
5090 resource .TestCheckResourceAttrSet ("tencentcloud_cynosdb_cluster.foo" , "storage_used" ),
0 commit comments