Skip to content

Commit b41e34d

Browse files
gitmknanonymous
andauthored
fix: modify teo unit (#1581)
Co-authored-by: anonymous <anonymous@mail.org>
1 parent 613e2d3 commit b41e34d

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

tencentcloud/resource_tc_teo_rule_engine_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,43 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
1212
)
1313

14+
func init() {
15+
// go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_teo_rule_engine
16+
resource.AddTestSweepers("tencentcloud_teo_rule_engine", &resource.Sweeper{
17+
Name: "tencentcloud_teo_rule_engine",
18+
F: testSweepRuleEngine,
19+
})
20+
}
21+
22+
func testSweepRuleEngine(region string) error {
23+
logId := getLogId(contextNil)
24+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
25+
cli, _ := sharedClientForRegion(region)
26+
client := cli.(*TencentCloudClient).apiV3Conn
27+
service := TeoService{client}
28+
29+
zoneId := defaultZoneId
30+
31+
records, err := service.DescribeTeoRuleEngines(ctx, zoneId)
32+
if err != nil {
33+
return err
34+
}
35+
36+
if len(records) < 1 {
37+
return nil
38+
}
39+
40+
for _, v := range records {
41+
if *v.RuleName == "rule-1" {
42+
err = service.DeleteTeoRuleEngineById(ctx, zoneId, *v.RuleId)
43+
if err != nil {
44+
return err
45+
}
46+
}
47+
}
48+
return nil
49+
}
50+
1451
// go test -i; go test -test.run TestAccTencentCloudTeoRuleEngine_basic -v
1552
func TestAccTencentCloudTeoRuleEngine_basic(t *testing.T) {
1653
t.Parallel()

tencentcloud/resource_tc_teo_zone_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func testSweepZone(region string) error {
2525
client := cli.(*TencentCloudClient).apiV3Conn
2626
service := TeoService{client}
2727

28-
zoneId := clusterPrometheusId
28+
zoneId := defaultZoneId
2929

3030
zone, err := service.DescribeTeoZone(ctx, zoneId)
3131
if err != nil {
@@ -57,7 +57,7 @@ func TestAccTencentCloudTeoZone_basic(t *testing.T) {
5757
Check: resource.ComposeTestCheckFunc(
5858
testAccCheckZoneExists("tencentcloud_teo_zone.basic"),
5959
resource.TestCheckResourceAttr("tencentcloud_teo_zone.basic", "zone_name", "tf-teo.xyz"),
60-
resource.TestCheckResourceAttr("tencentcloud_teo_zone.basic", "plan_type", "ent_with_bot"),
60+
resource.TestCheckResourceAttr("tencentcloud_teo_zone.basic", "plan_type", "sta"),
6161
resource.TestCheckResourceAttr("tencentcloud_teo_zone.basic", "type", "full"),
6262
resource.TestCheckResourceAttr("tencentcloud_teo_zone.basic", "paused", "false"),
6363
resource.TestCheckResourceAttr("tencentcloud_teo_zone.basic", "cname_speed_up", "enabled"),
@@ -120,7 +120,7 @@ const testAccTeoZone = `
120120
121121
resource "tencentcloud_teo_zone" "basic" {
122122
cname_speed_up = "enabled"
123-
plan_type = "ent_with_bot"
123+
plan_type = "sta"
124124
paused = false
125125
type = "full"
126126
zone_name = "tf-teo.xyz"

tencentcloud/service_tencentcloud_teo.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,40 @@ func (me *TeoService) DescribeTeoRuleEngine(ctx context.Context, zoneId, ruleId
420420

421421
}
422422

423+
func (me *TeoService) DescribeTeoRuleEngines(ctx context.Context, zoneId string) (ruleEngines []*teo.RuleItem,
424+
errRet error) {
425+
var (
426+
logId = getLogId(ctx)
427+
request = teo.NewDescribeRulesRequest()
428+
)
429+
430+
defer func() {
431+
if errRet != nil {
432+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
433+
logId, "query object", request.ToJsonString(), errRet.Error())
434+
}
435+
}()
436+
437+
request.ZoneId = &zoneId
438+
ratelimit.Check(request.GetAction())
439+
response, err := me.client.UseTeoClient().DescribeRules(request)
440+
if err != nil {
441+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
442+
logId, request.GetAction(), request.ToJsonString(), err.Error())
443+
errRet = err
444+
return
445+
}
446+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
447+
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
448+
449+
if response != nil && response.Response != nil && response.Response.RuleItems != nil {
450+
ruleEngines = response.Response.RuleItems
451+
}
452+
453+
return
454+
455+
}
456+
423457
func (me *TeoService) DeleteTeoRuleEngineById(ctx context.Context, zoneId, ruleId string) (errRet error) {
424458
logId := getLogId(ctx)
425459

0 commit comments

Comments
 (0)