Skip to content

Commit e379543

Browse files
authored
Fix/teo unit (#1300)
* fix: unit update * fix: unit update * fix: unit update * fix: update unit * fix: update acccount type config * fix: update unit * fix: update unit * fix: update unit * fix: update unit * fix: update unit * fix: update unit * fix: update unit * fix: update unit * fix: update unit * fix: update unit * fix: update unit Co-authored-by: arunma <arunma@tencent.com>
1 parent b5d60f9 commit e379543

27 files changed

+1344
-478
lines changed

tencentcloud/basic_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,3 +772,13 @@ locals {
772772
`
773773

774774
// End of MongoDB
775+
776+
// TEO
777+
778+
const (
779+
defaultZoneName = "tf-teo-t.xyz"
780+
defaultZoneId = "zone-2a1u0y616jz6"
781+
defaultPolicyId = "11587"
782+
)
783+
784+
// End of TEO

tencentcloud/data_source_tc_teo_bot_managed_rules_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
77
)
88

9+
// go test -i; go test -test.run TestAccTencentCloudTeoBotManagedRulesDataSource -v
910
func TestAccTencentCloudTeoBotManagedRulesDataSource(t *testing.T) {
1011
t.Parallel()
1112

@@ -23,11 +24,21 @@ func TestAccTencentCloudTeoBotManagedRulesDataSource(t *testing.T) {
2324
})
2425
}
2526

26-
const testAccDataSourceTeoBotManagedRules = `
27+
const testAccDataSourceTeoBotManagedRulesVar = `
28+
variable "zone_id" {
29+
default = "` + defaultZoneId + `"
30+
}
31+
32+
variable "entity" {
33+
default = "` + defaultZoneName + `"
34+
}
35+
`
36+
37+
const testAccDataSourceTeoBotManagedRules = testAccDataSourceTeoBotManagedRulesVar + `
2738
2839
data "tencentcloud_teo_bot_managed_rules" "bot_managed_rules" {
29-
zone_id = ""
30-
entity = ""
31-
}
40+
zone_id = var.zone_id
41+
entity = var.entity
42+
}
3243
3344
`

tencentcloud/data_source_tc_teo_bot_portrait_rules_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
77
)
88

9+
// go test -i; go test -test.run TestAccTencentCloudTeoBotPortraitRulesDataSource -v
910
func TestAccTencentCloudTeoBotPortraitRulesDataSource(t *testing.T) {
1011
t.Parallel()
1112

@@ -23,11 +24,21 @@ func TestAccTencentCloudTeoBotPortraitRulesDataSource(t *testing.T) {
2324
})
2425
}
2526

26-
const testAccDataSourceTeoBotPortraitRules = `
27+
const testAccDataSourceTeoBotPortraitRulesVar = `
28+
variable "zone_id" {
29+
default = "` + defaultZoneId + `"
30+
}
31+
32+
variable "entity" {
33+
default = "` + defaultZoneName + `"
34+
}
35+
`
36+
37+
const testAccDataSourceTeoBotPortraitRules = testAccDataSourceTeoBotPortraitRulesVar + `
2738
2839
data "tencentcloud_teo_bot_portrait_rules" "bot_portrait_rules" {
29-
zone_id = ""
30-
entity = ""
31-
}
40+
zone_id = var.zone_id
41+
entity = var.entity
42+
}
3243
3344
`

tencentcloud/data_source_tc_teo_rule_engine_settings_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
77
)
88

9+
// go test -i; go test -test.run TestAccTencentCloudTeoRuleEngineSettingsDataSource -v
910
func TestAccTencentCloudTeoRuleEngineSettingsDataSource(t *testing.T) {
1011
t.Parallel()
1112

@@ -26,6 +27,6 @@ func TestAccTencentCloudTeoRuleEngineSettingsDataSource(t *testing.T) {
2627
const testAccDataSourceTeoRuleEngineSettings = `
2728
2829
data "tencentcloud_teo_rule_engine_settings" "rule_engine_settings" {
29-
}
30+
}
3031
3132
`

tencentcloud/data_source_tc_teo_security_policy_regions_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
77
)
88

9+
// go test -i; go test -test.run TestAccTencentCloudTeoSecurityPolicyRegionsDataSource -v
910
func TestAccTencentCloudTeoSecurityPolicyRegionsDataSource(t *testing.T) {
1011
t.Parallel()
1112

@@ -26,6 +27,6 @@ func TestAccTencentCloudTeoSecurityPolicyRegionsDataSource(t *testing.T) {
2627
const testAccDataSourceTeoSecurityPolicyRegions = `
2728
2829
data "tencentcloud_teo_security_policy_regions" "security_policy_regions" {
29-
}
30+
}
3031
3132
`

tencentcloud/data_source_tc_teo_waf_rule_groups_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
77
)
88

9+
// go test -i; go test -test.run TestAccTencentCloudTeoWafRuleGroupsDataSource -v
910
func TestAccTencentCloudTeoWafRuleGroupsDataSource(t *testing.T) {
1011
t.Parallel()
1112

@@ -23,9 +24,21 @@ func TestAccTencentCloudTeoWafRuleGroupsDataSource(t *testing.T) {
2324
})
2425
}
2526

26-
const testAccDataSourceTeoWafRuleGroups = `
27+
const testAccDataSourceTeoWafRuleGroupsVar = `
28+
variable "zone_id" {
29+
default = "` + defaultZoneId + `"
30+
}
31+
32+
variable "entity" {
33+
default = "` + defaultZoneName + `"
34+
}
35+
`
36+
37+
const testAccDataSourceTeoWafRuleGroups = testAccDataSourceTeoWafRuleGroupsVar + `
2738
2839
data "tencentcloud_teo_waf_rule_groups" "waf_rule_groups" {
29-
}
40+
zone_id = var.zone_id
41+
entity = var.entity
42+
}
3043
3144
`

tencentcloud/data_source_tc_teo_zone_available_plans_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
77
)
88

9+
// go test -i; go test -test.run TestAccTencentCloudTeoZoneAvailablePlansDataSource -v
910
func TestAccTencentCloudTeoZoneAvailablePlansDataSource(t *testing.T) {
1011
t.Parallel()
1112

@@ -26,6 +27,6 @@ func TestAccTencentCloudTeoZoneAvailablePlansDataSource(t *testing.T) {
2627
const testAccDataSourceTeoZoneAvailablePlans = `
2728
2829
data "tencentcloud_teo_zone_available_plans" "zone_available_plans" {
29-
}
30+
}
3031
3132
`

tencentcloud/data_source_tc_teo_zone_ddos_policy_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
77
)
88

9+
// go test -i; go test -test.run TestAccTencentCloudTeoZoneDDoSPolicyDataSource -v
910
func TestAccTencentCloudTeoZoneDDoSPolicyDataSource(t *testing.T) {
1011
t.Parallel()
1112

@@ -23,10 +24,16 @@ func TestAccTencentCloudTeoZoneDDoSPolicyDataSource(t *testing.T) {
2324
})
2425
}
2526

26-
const testAccDataSourceTeoZoneDDoSPolicy = `
27+
const testAccDataSourceTeoZoneDDoSPolicyVar = `
28+
variable "zone_id" {
29+
default = "` + defaultZoneId + `"
30+
}
31+
`
32+
33+
const testAccDataSourceTeoZoneDDoSPolicy = testAccDataSourceTeoZoneDDoSPolicyVar + `
2734
2835
data "tencentcloud_teo_zone_ddos_policy" "zone_ddos_policy" {
29-
zone_id = ""
36+
zone_id = var.zone_id
3037
}
3138
3239
`
Lines changed: 90 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,124 @@
11
package tencentcloud
22

33
import (
4+
"context"
5+
"fmt"
6+
"strings"
47
"testing"
58

9+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
10+
611
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
712
)
813

9-
func TestAccTencentCloudNeedFixTeoApplicationProxyRule_basic(t *testing.T) {
14+
// go test -i; go test -test.run TestAccTencentCloudTeoApplicationProxyRule_basic -v
15+
func TestAccTencentCloudTeoApplicationProxyRule_basic(t *testing.T) {
1016
t.Parallel()
11-
1217
resource.Test(t, resource.TestCase{
13-
PreCheck: func() { testAccPreCheck(t) },
14-
Providers: testAccProviders,
18+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PRIVATE) },
19+
Providers: testAccProviders,
20+
CheckDestroy: testAccCheckApplicationProxyRuleDestroy,
1521
Steps: []resource.TestStep{
1622
{
1723
Config: testAccTeoApplicationProxyRule,
1824
Check: resource.ComposeTestCheckFunc(
19-
resource.TestCheckResourceAttrSet("tencentcloud_teo_application_proxy_rule.application_proxy_rule", "id"),
25+
testAccCheckApplicationProxyRuleExists("tencentcloud_teo_application_proxy_rule.basic"),
26+
//resource.TestCheckResourceAttr("tencentcloud_teo_application_proxy_rule.basic", "zone_name", "tf-teo.com"),
27+
//resource.TestCheckResourceAttr("tencentcloud_teo_application_proxy_rule.basic", "plan_type", "ent_with_bot"),
2028
),
2129
},
2230
{
23-
ResourceName: "tencentcloud_teo_application_proxy_rule.application_proxy_rule",
31+
ResourceName: "tencentcloud_teo_application_proxy_rule.basic",
2432
ImportState: true,
2533
ImportStateVerify: true,
2634
},
2735
},
2836
})
2937
}
3038

31-
const testAccTeoApplicationProxyRule = `
39+
func testAccCheckApplicationProxyRuleDestroy(s *terraform.State) error {
40+
logId := getLogId(contextNil)
41+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
42+
service := TeoService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
43+
for _, rs := range s.RootModule().Resources {
44+
if rs.Type != "tencentcloud_teo_application_proxy_rule" {
45+
continue
46+
}
47+
idSplit := strings.Split(rs.Primary.ID, FILED_SP)
48+
if len(idSplit) != 3 {
49+
return fmt.Errorf("id is broken,%s", rs.Primary.ID)
50+
}
51+
zoneId := idSplit[0]
52+
proxyId := idSplit[1]
53+
ruleId := idSplit[2]
54+
55+
agents, err := service.DescribeTeoApplicationProxyRule(ctx, zoneId, proxyId, ruleId)
56+
if agents != nil {
57+
return fmt.Errorf("zone ApplicationProxyRule %s still exists", rs.Primary.ID)
58+
}
59+
if err != nil {
60+
return err
61+
}
62+
}
63+
return nil
64+
}
65+
66+
func testAccCheckApplicationProxyRuleExists(r string) resource.TestCheckFunc {
67+
return func(s *terraform.State) error {
68+
logId := getLogId(contextNil)
69+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
70+
71+
rs, ok := s.RootModule().Resources[r]
72+
if !ok {
73+
return fmt.Errorf("resource %s is not found", r)
74+
}
75+
76+
idSplit := strings.Split(rs.Primary.ID, FILED_SP)
77+
if len(idSplit) != 3 {
78+
return fmt.Errorf("id is broken,%s", rs.Primary.ID)
79+
}
80+
zoneId := idSplit[0]
81+
proxyId := idSplit[1]
82+
ruleId := idSplit[2]
83+
84+
service := TeoService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
85+
agents, err := service.DescribeTeoApplicationProxyRule(ctx, zoneId, proxyId, ruleId)
86+
if agents == nil {
87+
return fmt.Errorf("zone ApplicationProxyRule %s is not found", rs.Primary.ID)
88+
}
89+
if err != nil {
90+
return err
91+
}
92+
93+
return nil
94+
}
95+
}
96+
97+
const testAccTeoApplicationProxyRuleVar = `
98+
variable "default_zone_id" {
99+
default = "` + defaultZoneId + `"
100+
}
101+
variable "proxy_id" {
102+
default = "` + defaultPolicyId + `"
103+
}
104+
`
32105

33-
resource "tencentcloud_teo_application_proxy_rule" "application_proxy_rule" {
34-
zone_id = tencentcloud_teo_zone.zone.id
35-
proxy_id = tencentcloud_teo_application_proxy.application_proxy_rule.proxy_id
106+
const testAccTeoApplicationProxyRule = testAccTeoApplicationProxyRuleVar + testAccTeoApplicationProxy + `
36107
108+
resource "tencentcloud_teo_application_proxy_rule" "basic" {
37109
forward_client_ip = "TOA"
38110
origin_type = "custom"
39111
origin_value = [
40-
"1.1.1.1:80",
112+
"127.0.0.1:8081",
41113
]
42-
port = [
43-
"80",
114+
port = [
115+
"8083",
44116
]
45-
proto = "TCP"
46-
session_persist = false
117+
proto = "TCP"
118+
proxy_id = tencentcloud_teo_application_proxy.basic.proxy_id
119+
session_persist = false
120+
status = "online"
121+
zone_id = var.default_zone_id
47122
}
48123
49124
`

0 commit comments

Comments
 (0)