Skip to content

Commit 5920880

Browse files
authored
fix: cynosdb testcase (#906)
* fix: cynosdb testcase * fix: cynosdb testcase expected charset
1 parent f4707b9 commit 5920880

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

tencentcloud/resource_tc_cynosdb_cluster_test.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,52 @@ package tencentcloud
33
import (
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+
1252
func 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

Comments
 (0)