@@ -4,13 +4,88 @@ import (
44 "context"
55 "errors"
66 "fmt"
7+ "strings"
78 "testing"
9+ "time"
810
911 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
1012 "github.com/hashicorp/terraform-plugin-sdk/terraform"
1113 sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
1214)
1315
16+ func init () {
17+ // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_gaap_layer7_listener
18+ resource .AddTestSweepers ("tencentcloud_gaap_layer7_listener" , & resource.Sweeper {
19+ Name : "tencentcloud_gaap_layer7_listener" ,
20+ F : func (r string ) error {
21+ logId := getLogId (contextNil )
22+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
23+ sharedClient , err := sharedClientForRegion (r )
24+ if err != nil {
25+ return fmt .Errorf ("getting tencentcloud client error: %s" , err .Error ())
26+ }
27+ client := sharedClient .(* TencentCloudClient )
28+ service := GaapService {client : client .apiV3Conn }
29+ proxyIds := []string {defaultGaapProxyId , defaultGaapProxyId2 }
30+ for _ , proxyId := range proxyIds {
31+ proxyIdTmp := proxyId
32+ httpListeners , err := service .DescribeHTTPListeners (ctx , & proxyIdTmp , nil , nil , nil )
33+ if err != nil {
34+ return err
35+ }
36+ for _ , httpListener := range httpListeners {
37+ instanceName := * httpListener .ListenerName
38+
39+ now := time .Now ()
40+ createTime := time .Unix (int64 (* httpListener .CreateTime ), 0 )
41+ interval := now .Sub (createTime ).Minutes ()
42+
43+ if strings .HasPrefix (instanceName , keepResource ) || strings .HasPrefix (instanceName , defaultResource ) {
44+ continue
45+ }
46+
47+ if needProtect == 1 && int64 (interval ) < 30 {
48+ continue
49+ }
50+
51+ ee := service .DeleteLayer7Listener (ctx , * httpListener .ListenerId , proxyId , * httpListener .Protocol )
52+ if ee != nil {
53+ continue
54+ }
55+
56+ }
57+ httpsListeners , err := service .DescribeHTTPSListeners (ctx , & proxyIdTmp , nil , nil , nil )
58+ if err != nil {
59+ return err
60+ }
61+
62+ for _ , httpsListener := range httpsListeners {
63+ instanceName := * httpsListener .ListenerName
64+
65+ now := time .Now ()
66+ createTime := time .Unix (int64 (* httpsListener .CreateTime ), 0 )
67+ interval := now .Sub (createTime ).Minutes ()
68+
69+ if strings .HasPrefix (instanceName , keepResource ) || strings .HasPrefix (instanceName , defaultResource ) {
70+ continue
71+ }
72+
73+ if needProtect == 1 && int64 (interval ) < 30 {
74+ continue
75+ }
76+
77+ ee := service .DeleteLayer7Listener (ctx , * httpsListener .ListenerId , proxyId , * httpsListener .Protocol )
78+ if ee != nil {
79+ continue
80+ }
81+
82+ }
83+ }
84+ return nil
85+ },
86+ })
87+ }
88+
1489func TestAccTencentCloudGaapLayer7Listener_basic (t * testing.T ) {
1590 t .Parallel ()
1691 id := new (string )
0 commit comments