Skip to content

Commit

Permalink
Add test for #36975.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Apr 18, 2024
1 parent 322215b commit 4c530cd
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion internal/conns/apiretry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ package conns

import (
"errors"
"net/http"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/retry"
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
appconfigtypes "github.com/aws/aws-sdk-go-v2/service/appconfig/types"
smithy "github.com/aws/smithy-go"
smithyhttp "github.com/aws/smithy-go/transport/http"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
)

Expand All @@ -24,18 +29,57 @@ func TestAddIsErrorRetryables(t *testing.T) {
testCases := []struct {
name string
err error
f retry.IsErrorRetryableFunc
expected bool
}{
{
name: "no error",
f: f,
},
{
name: "non-retryable",
err: errors.New(`this is not retryable`),
f: f,
},
{
name: "retryable",
err: errors.New(`this is testing`),
f: f,
expected: true,
},
{
// https://github.com/hashicorp/terraform-provider-aws/issues/36975.
name: "appconfig ConflictException",
err: &smithy.OperationError{
ServiceID: "AppConfig",
OperationName: "StartDeployment",
Err: &awshttp.ResponseError{
ResponseError: &smithyhttp.ResponseError{
Response: &smithyhttp.Response{
Response: &http.Response{
StatusCode: 409,
},
},
Err: &appconfigtypes.ConflictException{
Message: aws.String("Deployment number 1 already exists"),
},
},
RequestID: "43e844da-818b-458e-aae2-553960ccc4d6",
},
},
f: func(err error) aws.Ternary {
if err != nil {
var oe *smithy.OperationError
if errors.As(err, &oe) {
if oe.OperationName == "StartDeployment" {
if errs.IsA[*appconfigtypes.ConflictException](err) {
return aws.TrueTernary
}
}
}
}
return aws.UnknownTernary
},
expected: true,
},
}
Expand All @@ -45,7 +89,7 @@ func TestAddIsErrorRetryables(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

got := AddIsErrorRetryables(retry.NewStandard(), retry.IsErrorRetryableFunc(f)).IsErrorRetryable(testCase.err)
got := AddIsErrorRetryables(retry.NewStandard(), retry.IsErrorRetryableFunc(testCase.f)).IsErrorRetryable(testCase.err)
if got, want := got, testCase.expected; got != want {
t.Errorf("IsErrorRetryable(%q) = %v, want %v", testCase.err, got, want)
}
Expand Down

0 comments on commit 4c530cd

Please sign in to comment.