Skip to content

Commit fbdb605

Browse files
authored
fix: modify cynosdb test (#2063)
1 parent 9f414ac commit fbdb605

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

tencentcloud/resource_tc_cynosdb_cluster_password_complexity_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestAccTencentCloudCynosdbClusterPasswordComplexityResource_basic(t *testin
2222
Check: resource.ComposeTestCheckFunc(
2323
testAccCheckCynosdbClusterPasswordComplexityExists("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity"),
2424
resource.TestCheckResourceAttrSet("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity", "id"),
25-
resource.TestCheckResourceAttr("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity", "cluster_id", "cynosdbmysql-cgd2gpwr"),
25+
resource.TestCheckResourceAttr("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity", "cluster_id", defaultCynosdbClusterId),
2626
resource.TestCheckResourceAttr("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity", "validate_password_length", "8"),
2727
resource.TestCheckResourceAttr("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity", "validate_password_mixed_case_count", "1"),
2828
resource.TestCheckResourceAttr("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity", "validate_password_special_char_count", "1"),
@@ -41,7 +41,7 @@ func TestAccTencentCloudCynosdbClusterPasswordComplexityResource_basic(t *testin
4141
Check: resource.ComposeTestCheckFunc(
4242
testAccCheckCynosdbClusterPasswordComplexityExists("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity"),
4343
resource.TestCheckResourceAttrSet("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity", "id"),
44-
resource.TestCheckResourceAttr("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity", "cluster_id", "cynosdbmysql-cgd2gpwr"),
44+
resource.TestCheckResourceAttr("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity", "cluster_id", defaultCynosdbClusterId),
4545
resource.TestCheckResourceAttr("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity", "validate_password_length", "10"),
4646
resource.TestCheckResourceAttr("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity", "validate_password_mixed_case_count", "2"),
4747
resource.TestCheckResourceAttr("tencentcloud_cynosdb_cluster_password_complexity.cluster_password_complexity", "validate_password_special_char_count", "2"),
@@ -104,10 +104,10 @@ func testAccCheckCynosdbClusterPasswordComplexityExists(n string) resource.TestC
104104
}
105105
}
106106

107-
const testAccCynosdbClusterPasswordComplexity = `
107+
const testAccCynosdbClusterPasswordComplexity = CommonCynosdb + `
108108
109109
resource "tencentcloud_cynosdb_cluster_password_complexity" "cluster_password_complexity" {
110-
cluster_id = "cynosdbmysql-cgd2gpwr"
110+
cluster_id = var.cynosdb_cluster_id
111111
validate_password_length = 8
112112
validate_password_mixed_case_count = 1
113113
validate_password_special_char_count = 1
@@ -122,10 +122,10 @@ resource "tencentcloud_cynosdb_cluster_password_complexity" "cluster_password_co
122122
123123
`
124124

125-
const testAccCynosdbClusterPasswordComplexityUp = `
125+
const testAccCynosdbClusterPasswordComplexityUp = CommonCynosdb + `
126126
127127
resource "tencentcloud_cynosdb_cluster_password_complexity" "cluster_password_complexity" {
128-
cluster_id = "cynosdbmysql-cgd2gpwr"
128+
cluster_id = var.cynosdb_cluster_id
129129
validate_password_length = 10
130130
validate_password_mixed_case_count = 2
131131
validate_password_special_char_count = 2

tencentcloud/resource_tc_cynosdb_param_template.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,38 @@ func resourceTencentCloudCynosdbParamTemplateRead(d *schema.ResourceData, meta i
206206
_ = d.Set("db_mode", paramTemplate.DbMode)
207207
}
208208

209+
params := make([]string, 0)
210+
if v, ok := d.GetOk("param_list"); ok {
211+
for _, item := range v.(*schema.Set).List() {
212+
if item != nil {
213+
dMap := item.(map[string]interface{})
214+
if v, ok := dMap["param_name"]; ok {
215+
params = append(params, v.(string))
216+
}
217+
}
218+
}
219+
}
220+
209221
if paramTemplate.Items != nil {
210-
paramInfoSetList := []interface{}{}
211-
for _, paramInfoSet := range paramTemplate.Items {
212-
paramInfoSetList = append(paramInfoSetList, map[string]interface{}{
213-
"param_name": *paramInfoSet.ParamName,
214-
"current_value": *paramInfoSet.CurrentValue,
215-
})
222+
if len(params) > 0 {
223+
paramInfoSetList := make([]map[string]interface{}, 0, len(params))
224+
for _, param := range params {
225+
for _, paramList := range paramTemplate.Items {
226+
if *paramList.ParamName == param {
227+
paramListMap := map[string]interface{}{}
228+
if paramList.ParamName != nil {
229+
paramListMap["param_name"] = paramList.ParamName
230+
}
231+
if paramList.CurrentValue != nil {
232+
paramListMap["current_value"] = paramList.CurrentValue
233+
}
234+
paramInfoSetList = append(paramInfoSetList, paramListMap)
235+
break
236+
}
237+
}
238+
}
239+
_ = d.Set("param_list", paramInfoSetList)
216240
}
217-
_ = d.Set("param_list", paramInfoSetList)
218241
}
219242

220243
return nil

0 commit comments

Comments
 (0)