Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:adjust e2e sweeper #2137

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions tencentcloud/resource_tc_kubernetes_addon_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package tencentcloud
import (
"context"
"fmt"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
)

const defaultAddonName = "cos"
Expand All @@ -30,10 +32,17 @@ func init() {
return fmt.Errorf("no persistent cluster")
}

clusterId := cls[0].ClusterId

if err = service.DeleteExtensionAddon(ctx, clusterId, defaultAddonName); err != nil {
return err
for _, c := range cls {
clusterId := c.ClusterId
if err = service.DeleteExtensionAddon(ctx, clusterId, defaultAddonName); err != nil {
if e, ok := err.(*errors.TencentCloudSDKError); ok {
// suppress the not found error when cos doesn't exist
if strings.Contains(e.GetMessage(), "application cos not found") {
continue
}
}
return err
}
}

return nil
Expand Down
29 changes: 11 additions & 18 deletions tencentcloud/resource_tc_kubernetes_backup_storage_location_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import (
"testing"
"time"

"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525"
)

const (
Expand All @@ -24,7 +21,7 @@ const (

func init() {
// go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_backup_storage_location
resource.AddTestSweepers("testBackupStorageLocationSweep", &resource.Sweeper{
resource.AddTestSweepers("tencentcloud_backup_storage_location", &resource.Sweeper{
Name: "tencentcloud_backup_storage_location",
F: testBackupStorageLocationSweep,
})
Expand Down Expand Up @@ -69,23 +66,19 @@ func testBackupStorageLocationSweep(region string) error {
client := cli.(*TencentCloudClient).apiV3Conn
service := TkeService{client: client}

randomNum := rand.Intn(100)
backupStorageLocationName := fmt.Sprintf(backupStorageLocationNameTemplate, randomNum)
backupLocationBucket := fmt.Sprintf(backupLocationBucketTemplate, randomNum)

// create backup storage location
request := tke.NewCreateBackupStorageLocationRequest()
request.Name = helper.String(backupStorageLocationName)
request.StorageRegion = helper.String(region)
request.Bucket = helper.String(backupLocationBucket)
if err := service.createBackupStorageLocation(ctx, request); err != nil {
return fmt.Errorf("error creating backup storage location: %s", err)
// delete all backup storage location
locations, err := service.describeBackupStorageLocations(ctx, []string{})
if err != nil {
return err
}

// delete backup storage location
if err := service.deleteBackupStorageLocation(ctx, backupStorageLocationName); err != nil {
return fmt.Errorf("error deleting backup storage location: %s", err)
for _, l := range locations {
deleteLocation := l.Name
if err = service.deleteBackupStorageLocation(ctx, *deleteLocation); err != nil {
return fmt.Errorf("error deleting backup storage location: %s", err)
}
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ resource "tencentcloud_kubernetes_node_pool" "np_test" {
instance_type = var.ins_type
system_disk_type = "CLOUD_PREMIUM"
system_disk_size = "50"
security_group_ids = [local.sg_id]
orderly_security_group_ids = [local.sg_id]
cam_role_name = "TCB_QcsRole"
data_disk {
Expand Down
2 changes: 1 addition & 1 deletion tencentcloud/resource_tc_kubernetes_node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func init() {
})
}

var nodePoolNameReg = regexp.MustCompile("^(mynodepool|np)")
var nodePoolNameReg = regexp.MustCompile("^(mynodepool|np|gpu)")

func testNodePoolSweep(region string) error {
logId := getLogId(contextNil)
Expand Down
Loading