Skip to content

Commit

Permalink
Merge pull request #36724 from hashicorp/f-devopsguru-precheck
Browse files Browse the repository at this point in the history
r/aws_devopsguru(test): add service level pre-check
  • Loading branch information
jar-b authored Apr 5, 2024
2 parents 8f13faf + 6d9dc00 commit 565eb3a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"log"
"net"
"os"
"reflect"
"regexp"
Expand Down Expand Up @@ -1733,6 +1734,10 @@ func PreCheckSkipError(err error) bool {
if tfawserr.ErrCodeEquals(err, "ForbiddenException") {
return true
}
// Ignore missing API endpoints
if errs.IsA[*net.DNSError](err) {
return true
}
return false
}

Expand Down
16 changes: 16 additions & 0 deletions internal/service/devopsguru/devopsguru_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
package devopsguru_test

import (
"context"
"testing"

"github.com/aws/aws-sdk-go-v2/service/devopsguru"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
)

func TestAccDevOpsGuru_serial(t *testing.T) {
Expand Down Expand Up @@ -45,3 +48,16 @@ func TestAccDevOpsGuru_serial(t *testing.T) {

acctest.RunSerialTests2Levels(t, testCases, 0)
}

func testAccPreCheck(ctx context.Context, t *testing.T) {
conn := acctest.Provider.Meta().(*conns.AWSClient).DevOpsGuruClient(ctx)

_, err := conn.DescribeAccountHealth(ctx, &devopsguru.DescribeAccountHealthInput{})

if acctest.PreCheckSkipError(err) {
t.Skipf("skipping acceptance testing: %s", err)
}
if err != nil {
t.Fatalf("unexpected PreCheck error: %s", err)
}
}
2 changes: 2 additions & 0 deletions internal/service/devopsguru/event_sources_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func testAccEventSourcesConfig_basic(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down Expand Up @@ -60,6 +61,7 @@ func testAccEventSourcesConfig_disappears(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func testAccNotificationChannelDataSource_basic(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down
3 changes: 3 additions & 0 deletions internal/service/devopsguru/notification_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func testAccNotificationChannel_basic(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down Expand Up @@ -65,6 +66,7 @@ func testAccNotificationChannel_disappears(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down Expand Up @@ -95,6 +97,7 @@ func testAccNotificationChannel_filters(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func testAccResourceCollectionDataSource_basic(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down
5 changes: 5 additions & 0 deletions internal/service/devopsguru/resource_collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func testAccResourceCollection_basic(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down Expand Up @@ -71,6 +72,7 @@ func testAccResourceCollection_disappears(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down Expand Up @@ -99,6 +101,7 @@ func testAccResourceCollection_cloudformation(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down Expand Up @@ -134,6 +137,7 @@ func testAccResourceCollection_tags(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down Expand Up @@ -170,6 +174,7 @@ func testAccResourceCollection_tagsAllResources(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down
2 changes: 2 additions & 0 deletions internal/service/devopsguru/service_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func testAccServiceIntegration_basic(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down Expand Up @@ -72,6 +73,7 @@ func testAccServiceIntegration_kms(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down

0 comments on commit 565eb3a

Please sign in to comment.