Skip to content

Commit

Permalink
Merge pull request #38590 from acwwat/td-aws_cloudsearch_domain-add_n…
Browse files Browse the repository at this point in the history
…ot_authorized_precheck

chore: Add domain creation allowlist precheck for CloudSearch tests
  • Loading branch information
jar-b committed Jul 30, 2024
2 parents 024ca45 + ac5005b commit 961823a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
17 changes: 17 additions & 0 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
accounttypes "github.com/aws/aws-sdk-go-v2/service/account/types"
"github.com/aws/aws-sdk-go-v2/service/acmpca"
acmpcatypes "github.com/aws/aws-sdk-go-v2/service/acmpca/types"
"github.com/aws/aws-sdk-go-v2/service/cloudsearch"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go-v2/service/costexplorer"
"github.com/aws/aws-sdk-go-v2/service/directoryservice"
Expand Down Expand Up @@ -1042,6 +1043,22 @@ func PreCheckCECostCategoryPayerAccount(ctx context.Context, t *testing.T) {
}
}

func PreCheckCloudSearchAccountAllowListed(ctx context.Context, t *testing.T) {
t.Helper()

conn := Provider.Meta().(*conns.AWSClient).CloudSearchClient(ctx)

_, err := conn.ListDomainNames(ctx, &cloudsearch.ListDomainNamesInput{})

if errs.MessageContains(err, "NotAuthorized", "New domain creation not supported on this account") {
t.Skip("skipping tests; this AWS account does not support new CloudSearch domain creation")
}

if err != nil {
t.Fatalf("listing CloudSearch Domain Names: %s", err)
}
}

func PreCheckInspector2(ctx context.Context, t *testing.T) {
t.Helper()

Expand Down
12 changes: 10 additions & 2 deletions internal/service/cloudsearch/domain_service_access_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ func TestAccCloudSearchDomainServiceAccessPolicy_basic(t *testing.T) {
rName := acctest.ResourcePrefix + "-" + sdkacctest.RandString(28-(len(acctest.ResourcePrefix)+1))

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID)
acctest.PreCheckCloudSearchAccountAllowListed(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CloudSearchServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainServiceAccessPolicyDestroy(ctx),
Expand All @@ -51,7 +55,11 @@ func TestAccCloudSearchDomainServiceAccessPolicy_update(t *testing.T) {
rName := acctest.ResourcePrefix + "-" + sdkacctest.RandString(28-(len(acctest.ResourcePrefix)+1))

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID)
acctest.PreCheckCloudSearchAccountAllowListed(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CloudSearchServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainServiceAccessPolicyDestroy(ctx),
Expand Down
30 changes: 25 additions & 5 deletions internal/service/cloudsearch/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ func TestAccCloudSearchDomain_basic(t *testing.T) {
rName := testAccDomainName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID)
acctest.PreCheckCloudSearchAccountAllowListed(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CloudSearchServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Expand Down Expand Up @@ -65,7 +69,11 @@ func TestAccCloudSearchDomain_disappears(t *testing.T) {
rName := testAccDomainName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID)
acctest.PreCheckCloudSearchAccountAllowListed(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CloudSearchServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Expand All @@ -89,7 +97,11 @@ func TestAccCloudSearchDomain_indexFields(t *testing.T) {
rName := testAccDomainName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID)
acctest.PreCheckCloudSearchAccountAllowListed(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CloudSearchServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Expand Down Expand Up @@ -161,7 +173,11 @@ func TestAccCloudSearchDomain_sourceFields(t *testing.T) {
rName := testAccDomainName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID)
acctest.PreCheckCloudSearchAccountAllowListed(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CloudSearchServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Expand Down Expand Up @@ -236,7 +252,11 @@ func TestAccCloudSearchDomain_update(t *testing.T) {
rName := testAccDomainName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CloudSearchEndpointID)
acctest.PreCheckCloudSearchAccountAllowListed(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CloudSearchServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Expand Down

0 comments on commit 961823a

Please sign in to comment.