@@ -3,12 +3,55 @@ package tencentcloud
33import (
44 "context"
55 "fmt"
6+ "log"
67 "testing"
8+ "time"
79
810 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
911 "github.com/hashicorp/terraform-plugin-sdk/terraform"
1012)
1113
14+ func init () {
15+ // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_cfs_file_system
16+ resource .AddTestSweepers ("tencentcloud_cfs_file_system" , & resource.Sweeper {
17+ Name : "tencentcloud_cfs_file_system" ,
18+ F : func (r string ) error {
19+ logId := getLogId (contextNil )
20+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
21+ cli , _ := sharedClientForRegion (r )
22+ client := cli .(* TencentCloudClient ).apiV3Conn
23+
24+ service := CfsService {client }
25+
26+ fsList , err := service .DescribeFileSystem (ctx , "" , "" , "" )
27+ if err != nil {
28+ return err
29+ }
30+ for i := range fsList {
31+ item := fsList [i ]
32+ id := * item .FileSystemId
33+ name := * item .FsName
34+ created := time.Time {}
35+ if item .CreationTime != nil {
36+ if result , err := time .Parse (time .RFC3339 , * item .CreationTime ); err != nil {
37+ created = result
38+ }
39+ }
40+ if isResourcePersist (name , & created ) {
41+ continue
42+ }
43+ log .Printf ("%s -> %s will be sweep" , id , name )
44+ err = service .DeleteFileSystem (ctx , id )
45+ if err != nil {
46+ continue
47+ }
48+ }
49+
50+ return nil
51+ },
52+ })
53+ }
54+
1255func TestAccTencentCloudCfsFileSystem (t * testing.T ) {
1356 t .Parallel ()
1457 resource .Test (t , resource.TestCase {
0 commit comments