Repository: go-to-k/delstack
Pull request #89 (2023-01-27 11:49:06)

reafactor: change constant names


Patch:
diff --git a/internal/io/input.go b/internal/io/input.go
index a965f46..602bb51 100644
--- a/internal/io/input.go
+++ b/internal/io/input.go
@@ -9,7 +9,7 @@ import (
 	"github.com/AlecAivazis/survey/v2"
 )
 
-const selectionPageSize = 20
+const SelectionPageSize = 20
 
 func GetCheckboxes(label string, opts []string) []string {
 	res := []string{}
@@ -29,7 +29,7 @@ func GetSelection(label string, opts []string) string {
 	prompt := &survey.Select{
 		Message:  label,
 		Options:  opts,
-		PageSize: selectionPageSize,
+		PageSize: SelectionPageSize,
 	}
 	survey.AskOne(prompt, &res)
 
diff --git a/internal/operation/operator_factory.go b/internal/operation/operator_factory.go
index 5d49f39..e01f137 100644
--- a/internal/operation/operator_factory.go
+++ b/internal/operation/operator_factory.go
@@ -10,7 +10,7 @@ import (
 	"github.com/go-to-k/delstack/pkg/client"
 )
 
-const awsSDKRetryMaxAttempts = 3
+const SDKRetryMaxAttempts = 3
 
 type IOperatorFactory interface {
 	CreateStackOperator(targetResourceTypes []string) *StackOperator
@@ -35,7 +35,7 @@ func NewOperatorFactory(config aws.Config) *OperatorFactory {
 
 func (f *OperatorFactory) CreateStackOperator(targetResourceTypes []string) *StackOperator {
 	sdkCfnClient := cloudformation.NewFromConfig(f.config, func(o *cloudformation.Options) {
-		o.RetryMaxAttempts = awsSDKRetryMaxAttempts
+		o.RetryMaxAttempts = SDKRetryMaxAttempts
 		o.RetryMode = aws.RetryModeStandard
 	})
 	sdkCfnWaiter := cloudformation.NewStackDeleteCompleteWaiter(sdkCfnClient)
@@ -52,7 +52,7 @@ func (f *OperatorFactory) CreateStackOperator(targetResourceTypes []string) *Sta
 
 func (f *OperatorFactory) CreateBackupVaultOperator() *BackupVaultOperator {
 	sdkBackupClient := backup.NewFromConfig(f.config, func(o *backup.Options) {
-		o.RetryMaxAttempts = awsSDKRetryMaxAttempts
+		o.RetryMaxAttempts = SDKRetryMaxAttempts
 		o.RetryMode = aws.RetryModeStandard
 	})
 
@@ -65,7 +65,7 @@ func (f *OperatorFactory) CreateBackupVaultOperator() *BackupVaultOperator {
 
 func (f *OperatorFactory) CreateEcrOperator() *EcrOperator {
 	sdkEcrClient := ecr.NewFromConfig(f.config, func(o *ecr.Options) {
-		o.RetryMaxAttempts = awsSDKRetryMaxAttempts
+		o.RetryMaxAttempts = SDKRetryMaxAttempts
 		o.RetryMode = aws.RetryModeStandard
 	})
 
@@ -78,7 +78,7 @@ func (f *OperatorFactory) CreateEcrOperator() *EcrOperator {
 
 func (f *OperatorFactory) CreateRoleOperator() *RoleOperator {
 	sdkIamClient := iam.NewFromConfig(f.config, func(o *iam.Options) {
-		o.RetryMaxAttempts = awsSDKRetryMaxAttempts
+		o.RetryMaxAttempts = SDKRetryMaxAttempts
 		o.RetryMode = aws.RetryModeStandard
 	})
 
@@ -91,7 +91,7 @@ func (f *OperatorFactory) CreateRoleOperator() *RoleOperator {
 
 func (f *OperatorFactory) CreateBucketOperator() *BucketOperator {
 	sdkS3Client := s3.NewFromConfig(f.config, func(o *s3.Options) {
-		o.RetryMaxAttempts = awsSDKRetryMaxAttempts
+		o.RetryMaxAttempts = SDKRetryMaxAttempts
 		o.RetryMode = aws.RetryModeStandard
 	})
 
diff --git a/internal/operation/stack.go b/internal/operation/stack.go
index d6e77b1..4385df6 100644
--- a/internal/operation/stack.go
+++ b/internal/operation/stack.go
@@ -17,9 +17,9 @@ import (
 
 var _ IOperator = (*StackOperator)(nil)
 
-const stackNameRule = `^arn:aws:cloudformation:[^:]*:[0-9]*:stack/([^/]*)/.*$`
+const StackNameRule = `^arn:aws:cloudformation:[^:]*:[0-9]*:stack/([^/]*)/.*$`
 
-var stackNameRuleRegExp = regexp.MustCompile(stackNameRule)
+var StackNameRuleRegExp = regexp.MustCompile(StackNameRule)
 
 type StackOperator struct {
 	config              aws.Config
@@ -56,7 +56,7 @@ func (o *StackOperator) DeleteResources(ctx context.Context) error {
 		}
 		eg.Go(func() error {
 			defer sem.Release(1)
-			stackName := stackNameRuleRegExp.ReplaceAllString(aws.ToString(stack.PhysicalResourceId), `$1`)
+			stackName := StackNameRuleRegExp.ReplaceAllString(aws.ToString(stack.PhysicalResourceId), `$1`)
 
 			isRootStack := false
 			operatorFactory := NewOperatorFactory(o.config)
diff --git a/pkg/client/aws_config.go b/pkg/client/aws_config.go
index b6c5826..59ef04f 100644
--- a/pkg/client/aws_config.go
+++ b/pkg/client/aws_config.go
@@ -7,7 +7,7 @@ import (
 	"github.com/aws/aws-sdk-go-v2/config"
 )
 
-const defaultAwsRegion = "us-east-1"
+const DefaultAwsRegion = "us-east-1"
 
 func LoadAWSConfig(ctx context.Context, region string, profile string) (aws.Config, error) {
 	var (
@@ -29,7 +29,7 @@ func LoadAWSConfig(ctx context.Context, region string, profile string) (aws.Conf
 		cfg.Region = region
 	}
 	if cfg.Region == "" {
-		cfg.Region = defaultAwsRegion
+		cfg.Region = DefaultAwsRegion
 	}
 
 	return cfg, nil
diff --git a/pkg/client/cloudformation.go b/pkg/client/cloudformation.go
index fe2feef..7ef054b 100644
--- a/pkg/client/cloudformation.go
+++ b/pkg/client/cloudformation.go
@@ -9,7 +9,7 @@ import (
 	"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
 )
 
-const cloudFormationWaitNanoSecTime = time.Duration(4500000000000)
+const CloudFormationWaitNanoSecTime = time.Duration(4500000000000)
 
 type ICloudFormation interface {
 	DeleteStack(ctx context.Context, stackName *string, retainResources []string) error
@@ -67,7 +67,7 @@ func (c *CloudFormation) waitDeleteStack(ctx context.Context, stackName *string)
 		StackName: stackName,
 	}
 
-	err := c.waiter.Wait(ctx, input, cloudFormationWaitNanoSecTime)
+	err := c.waiter.Wait(ctx, input, CloudFormationWaitNanoSecTime)
 	if err != nil && !strings.Contains(err.Error(), "waiter state transitioned to Failure") {
 		return err
 	}
diff --git a/pkg/client/s3.go b/pkg/client/s3.go
index 599d75f..dcc47bd 100644
--- a/pkg/client/s3.go
+++ b/pkg/client/s3.go
@@ -13,7 +13,7 @@ import (
 	"golang.org/x/sync/semaphore"
 )
 
-const s3DeleteObjectsSizeLimit = 1000
+const S3DeleteObjectsSizeLimit = 1000
 
 var SleepTimeSecForS3 = 10
 
@@ -74,9 +74,9 @@ func (s *S3) DeleteObjects(ctx context.Context, bucketName *string, objects []ty
 	for {
 		inputObjects := []types.ObjectIdentifier{}
 
-		if len(nextObjects) > s3DeleteObjectsSizeLimit {
-			inputObjects = append(inputObjects, nextObjects[:s3DeleteObjectsSizeLimit]...)
-			nextObjects = nextObjects[s3DeleteObjectsSizeLimit:]
+		if len(nextObjects) > S3DeleteObjectsSizeLimit {
+			inputObjects = append(inputObjects, nextObjects[:S3DeleteObjectsSizeLimit]...)
+			nextObjects = nextObjects[S3DeleteObjectsSizeLimit:]
 		} else {
 			inputObjects = append(inputObjects, nextObjects...)
 			nextObjects = nil
diff --git a/pkg/client/waiter.go b/pkg/client/waiter.go
index 93e0f7b..190bbcb 100644
--- a/pkg/client/waiter.go
+++ b/pkg/client/waiter.go
@@ -8,7 +8,7 @@ import (
 	"time"
 )
 
-const maxRetryCount = 10
+const MaxRetryCount = 10
 
 // T: Input type for API Request.
 // U: Output type for API Response.
@@ -49,8 +49,8 @@ func Retry[T, U, V any](
 }
 
 func waitForRetry(ctx context.Context, retryCount int, sleepTimeSec int, targetResource *string, err error) error {
-	if retryCount > maxRetryCount {
-		errorDetail := err.Error() + "\nRetryCount(" + strconv.Itoa(maxRetryCount) + ") over, but failed to delete. "
+	if retryCount > MaxRetryCount {
+		errorDetail := err.Error() + "\nRetryCount(" + strconv.Itoa(MaxRetryCount) + ") over, but failed to delete. "
 		return fmt.Errorf("RetryCountOverError: %v, %v", *targetResource, errorDetail)
 	}
 


Test patch:
diff --git a/pkg/client/iam_test.go b/pkg/client/iam_test.go
index d1e0e73..98e3ab6 100644
--- a/pkg/client/iam_test.go
+++ b/pkg/client/iam_test.go
@@ -109,7 +109,7 @@ func TestIam_DeleteRole(t *testing.T) {
 					)
 				},
 			},
-			want:    fmt.Errorf("RetryCountOverError: test, operation error IAM: DeleteRole, api error Throttling: Rate exceeded\nRetryCount(" + strconv.Itoa(maxRetryCount) + ") over, but failed to delete. "),
+			want:    fmt.Errorf("RetryCountOverError: test, operation error IAM: DeleteRole, api error Throttling: Rate exceeded\nRetryCount(" + strconv.Itoa(MaxRetryCount) + ") over, but failed to delete. "),
 			wantErr: true,
 		},
 	}
@@ -277,7 +277,7 @@ func TestIam_ListAttachedRolePolicies(t *testing.T) {
 			},
 			want: want{
 				output: nil,
-				err:    fmt.Errorf("RetryCountOverError: test, operation error IAM: ListAttachedRolePolicies, api error Throttling: Rate exceeded\nRetryCount(" + strconv.Itoa(maxRetryCount) + ") over, but failed to delete. "),
+				err:    fmt.Errorf("RetryCountOverError: test, operation error IAM: ListAttachedRolePolicies, api error Throttling: Rate exceeded\nRetryCount(" + strconv.Itoa(MaxRetryCount) + ") over, but failed to delete. "),
 			},
 			wantErr: true,
 		},
@@ -487,7 +487,7 @@ func TestIam_ListAttachedRolePolicies(t *testing.T) {
 			},
 			want: want{
 				output: nil,
-				err:    fmt.Errorf("RetryCountOverError: test, operation error IAM: ListAttachedRolePolicies, api error Throttling: Rate exceeded\nRetryCount(" + strconv.Itoa(maxRetryCount) + ") over, but failed to delete. "),
+				err:    fmt.Errorf("RetryCountOverError: test, operation error IAM: ListAttachedRolePolicies, api error Throttling: Rate exceeded\nRetryCount(" + strconv.Itoa(MaxRetryCount) + ") over, but failed to delete. "),
 			},
 			wantErr: true,
 		},
@@ -654,7 +654,7 @@ func TestIam_DetachRolePolicies(t *testing.T) {
 					)
 				},
 			},
-			want:    fmt.Errorf("RetryCountOverError: test, operation error IAM: DetachRolePolicy, api error Throttling: Rate exceeded\nRetryCount(" + strconv.Itoa(maxRetryCount) + ") over, but failed to delete. "),
+			want:    fmt.Errorf("RetryCountOverError: test, operation error IAM: DetachRolePolicy, api error Throttling: Rate exceeded\nRetryCount(" + strconv.Itoa(MaxRetryCount) + ") over, but failed to delete. "),
 			wantErr: true,
 		},
 	}
@@ -766,7 +766,7 @@ func TestIam_DetachRolePolicy(t *testing.T) {
 					)
 				},
 			},
-			want:    fmt.Errorf("RetryCountOverError: test, operation error IAM: DetachRolePolicy, api error Throttling: Rate exceeded\nRetryCount(" + strconv.Itoa(maxRetryCount) + ") over, but failed to delete. "),
+			want:    fmt.Errorf("RetryCountOverError: test, operation error IAM: DetachRolePolicy, api error Throttling: Rate exceeded\nRetryCount(" + strconv.Itoa(MaxRetryCount) + ") over, but failed to delete. "),
 			wantErr: true,
 		},
 	}
@@ -916,7 +916,7 @@ func TestIam_CheckRoleExists(t *testing.T) {
 			},
 			want: want{
 				exists: false,
-				err:    fmt.Errorf("RetryCountOverError: test, operation error IAM: GetRole, api error Throttling: Rate exceeded\nRetryCount(" + strconv.Itoa(maxRetryCount) + ") over, but failed to delete. "),
+				err:    fmt.Errorf("RetryCountOverError: test, operation error IAM: GetRole, api error Throttling: Rate exceeded\nRetryCount(" + strconv.Itoa(MaxRetryCount) + ") over, but failed to delete. "),
 			},
 			wantErr: true,
 		},
diff --git a/pkg/client/s3_test.go b/pkg/client/s3_test.go
index 49e4db2..f1bdeea 100644
--- a/pkg/client/s3_test.go
+++ b/pkg/client/s3_test.go
@@ -123,7 +123,7 @@ func TestS3_DeleteBucket(t *testing.T) {
 func TestS3_DeleteObjects(t *testing.T) {
 	SleepTimeSecForS3 = 1
 	objectsOverLimit := []types.ObjectIdentifier{}
-	s3DeleteObjectsSizeOverLimit := s3DeleteObjectsSizeLimit*int(runtime.NumCPU())*2 + 1 // loop over cpu core size for channel waiting when next loop
+	s3DeleteObjectsSizeOverLimit := S3DeleteObjectsSizeLimit*int(runtime.NumCPU())*2 + 1 // loop over cpu core size for channel waiting when next loop
 	for i := 0; i < s3DeleteObjectsSizeOverLimit; i++ {
 		objectsOverLimit = append(objectsOverLimit, types.ObjectIdentifier{
 			Key:       aws.String("Key"),
@@ -305,7 +305,7 @@ func TestS3_DeleteObjects(t *testing.T) {
 			},
 			want: want{
 				output: nil,
-				err:    fmt.Errorf("RetryCountOverError: test, operation error S3: DeleteObjects, api error SlowDown\nRetryCount(" + strconv.Itoa(maxRetryCount) + ") over, but failed to delete. "),
+				err:    fmt.Errorf("RetryCountOverError: test, operation error S3: DeleteObjects, api error SlowDown\nRetryCount(" + strconv.Itoa(MaxRetryCount) + ") over, but failed to delete. "),
 			},
 			wantErr: true,
 		},
diff --git a/pkg/client/waiter_test.go b/pkg/client/waiter_test.go
index 888d1a7..a83c3b9 100644
--- a/pkg/client/waiter_test.go
+++ b/pkg/client/waiter_test.go
@@ -34,7 +34,7 @@ func TestRetry(t *testing.T) {
 					return true
 				},
 			},
-			want:    fmt.Errorf("RetryCountOverError: resource, ApiFuncError\nRetryCount(" + strconv.Itoa(maxRetryCount) + ") over, but failed to delete. "),
+			want:    fmt.Errorf("RetryCountOverError: resource, ApiFuncError\nRetryCount(" + strconv.Itoa(MaxRetryCount) + ") over, but failed to delete. "),
 			wantErr: true,
 		},
 		{
@@ -186,7 +186,7 @@ func Test_waitForRetry(t *testing.T) {
 			name: "retryCount = MaxRetryCount - 1: not error",
 			args: args{
 				ctx:                context.Background(),
-				retryCount:         maxRetryCount - 1,
+				retryCount:         MaxRetryCount - 1,
 				sleepTimeSec:       1,
 				targetResourceType: aws.String("resource"),
 				err:                fmt.Errorf("API Error"),
@@ -198,7 +198,7 @@ func Test_waitForRetry(t *testing.T) {
 			name: "retryCount = MaxRetryCount: not error",
 			args: args{
 				ctx:                context.Background(),
-				retryCount:         maxRetryCount,
+				retryCount:         MaxRetryCount,
 				sleepTimeSec:       1,
 				targetResourceType: aws.String("resource"),
 				err:                fmt.Errorf("API Error"),
@@ -210,12 +210,12 @@ func Test_waitForRetry(t *testing.T) {
 			name: "retryCount = MaxRetryCount + 1: RetryCountOverError",
 			args: args{
 				ctx:                context.Background(),
-				retryCount:         maxRetryCount + 1,
+				retryCount:         MaxRetryCount + 1,
 				sleepTimeSec:       1,
 				targetResourceType: aws.String("resource"),
 				err:                fmt.Errorf("API Error"),
 			},
-			want:    fmt.Errorf("RetryCountOverError: resource, API Error\nRetryCount(" + strconv.Itoa(maxRetryCount) + ") over, but failed to delete. "),
+			want:    fmt.Errorf("RetryCountOverError: resource, API Error\nRetryCount(" + strconv.Itoa(MaxRetryCount) + ") over, but failed to delete. "),
 			wantErr: true,
 		},
 	}