Skip to content

Commit

Permalink
r/aws_devopsguru(test): add service level pre-check
Browse files Browse the repository at this point in the history
This pre-check captures operation errors observed when calling DevOps Guru in certain non-commercial partitions, such as GovCloud.

Before:

```
Error: creating Amazon DevOps Guru Notification Channel: operation error DevOps Guru: AddNotificationChannel, https response error StatusCode: 0, RequestID: , request send failed, Put "https://devops-guru.us-gov-east-1.amazonaws.com/channels": dial tcp: lookup devops-guru.us-gov-east-1.amazonaws.com: no such host
```

GovCloud:

```console
% make testacc PKG=devopsguru TESTS=TestAccDevOpsGuru_serial
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.21.8 test ./internal/service/devopsguru/... -v -count 1 -parallel 20 -run='TestAccDevOpsGuru_serial'  -timeout 360m
=== RUN   TestAccDevOpsGuru_serial
=== PAUSE TestAccDevOpsGuru_serial
=== CONT  TestAccDevOpsGuru_serial
    devopsguru_test.go:72: skipping acceptance testing: operation error DevOps Guru: DescribeAccountHealth, https response error StatusCode: 0, RequestID: , request send failed, Get "https://devops-guru.us-gov-east-1.amazonaws.com/accounts/health": dial tcp: lookup devops-guru.us-gov-east-1.amazonaws.com: no such host
--- SKIP: TestAccDevOpsGuru_serial (0.17s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/devopsguru 5.651s
```

Commercial:

```console
% make testacc PKG=devopsguru TESTS=TestAccDevOpsGuru_serial
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.21.8 test ./internal/service/devopsguru/... -v -count 1 -parallel 20 -run='TestAccDevOpsGuru_serial'  -timeout 360m

--- PASS: TestAccDevOpsGuru_serial (222.18s)
    --- PASS: TestAccDevOpsGuru_serial/ServiceIntegration (38.19s)
        --- PASS: TestAccDevOpsGuru_serial/ServiceIntegration/basic (18.19s)
        --- PASS: TestAccDevOpsGuru_serial/ServiceIntegration/kms (20.00s)
    --- PASS: TestAccDevOpsGuru_serial/EventSourcesConfig (20.63s)
        --- PASS: TestAccDevOpsGuru_serial/EventSourcesConfig/basic (11.15s)
        --- PASS: TestAccDevOpsGuru_serial/EventSourcesConfig/disappears (9.48s)
    --- PASS: TestAccDevOpsGuru_serial/NotificationChannel (38.04s)
        --- PASS: TestAccDevOpsGuru_serial/NotificationChannel/basic (13.16s)
        --- PASS: TestAccDevOpsGuru_serial/NotificationChannel/disappears (11.58s)
        --- PASS: TestAccDevOpsGuru_serial/NotificationChannel/filters (13.29s)
    --- PASS: TestAccDevOpsGuru_serial/NotificationChannelDataSource (11.37s)
        --- PASS: TestAccDevOpsGuru_serial/NotificationChannelDataSource/basic (11.37s)
    --- PASS: TestAccDevOpsGuru_serial/ResourceCollection (103.72s)
        --- PASS: TestAccDevOpsGuru_serial/ResourceCollection/disappears (9.60s)
        --- PASS: TestAccDevOpsGuru_serial/ResourceCollection/tags (11.27s)
        --- PASS: TestAccDevOpsGuru_serial/ResourceCollection/tagsAllResources (11.38s)
        --- PASS: TestAccDevOpsGuru_serial/ResourceCollection/basic (11.37s)
        --- PASS: TestAccDevOpsGuru_serial/ResourceCollection/cloudformation (60.10s)
    --- PASS: TestAccDevOpsGuru_serial/ResourceCollectionDataSource (9.42s)
        --- PASS: TestAccDevOpsGuru_serial/ResourceCollectionDataSource/basic (9.42s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/devopsguru 227.638s
```
  • Loading branch information
jar-b committed Apr 3, 2024
1 parent 5a9d0cb commit d1ce462
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 0 deletions.
26 changes: 26 additions & 0 deletions internal/service/devopsguru/devopsguru_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
package devopsguru_test

import (
"context"
"errors"
"net"
"strings"
"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 +51,23 @@ 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)
}
// In GovCloud partitions, API calls trigger an operation error
var netOpErr *net.OpError
if errors.As(err, &netOpErr) {
if strings.Contains(netOpErr.Error(), "no such host") {
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 d1ce462

Please sign in to comment.