Skip to content

Commit

Permalink
r/aws_amplify_app: Add test sweeper.
Browse files Browse the repository at this point in the history
Acceptance test output:

% TEST=./aws SWEEP=us-west-2 SWEEPARGS=-sweep-run=aws_amplify_app make sweep
WARNING: This will destroy infrastructure. Use only in development accounts.
go test ./aws -v -sweep=us-west-2 -sweep-run=aws_amplify_app -timeout 60m
2021/05/20 11:13:49 [DEBUG] Running Sweepers for region (us-west-2):
2021/05/20 11:13:49 [DEBUG] Running Sweeper (aws_amplify_app) in region (us-west-2)
2021/05/20 11:13:49 [INFO] AWS Auth provider used: "EnvProvider"
2021/05/20 11:13:49 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2021/05/20 11:13:50 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2021/05/20 11:13:50 [DEBUG] Deleting Amplify App (d3e2rpqo82owxg)
2021/05/20 11:13:51 Sweeper Tests ran successfully:
	- aws_amplify_app
ok  	github.com/terraform-providers/terraform-provider-aws/aws	4.452s
  • Loading branch information
ewbankkit committed May 20, 2021
1 parent 407f9fe commit 6bc6406
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
3 changes: 3 additions & 0 deletions aws/internal/service/amplify/lister/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//go:generate go run ../../../generators/listpages/main.go -function=ListApps github.com/aws/aws-sdk-go/service/amplify

package lister
31 changes: 31 additions & 0 deletions aws/internal/service/amplify/lister/list_pages_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 51 additions & 1 deletion aws/resource_aws_amplify_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,70 @@ package aws
import (
"encoding/base64"
"fmt"
"log"
"os"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/amplify"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/amplify/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/amplify/lister"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

// TODO sweeper
func init() {
resource.AddTestSweepers("aws_amplify_app", &resource.Sweeper{
Name: "aws_amplify_app",
F: testSweepAmplifyApps,
})
}

func testSweepAmplifyApps(region string) error {
client, err := sharedClientForRegion(region)
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*AWSClient).amplifyconn
input := &amplify.ListAppsInput{}
var sweeperErrs *multierror.Error

err = lister.ListAppsPages(conn, input, func(page *amplify.ListAppsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, app := range page.Apps {
r := resourceAwsAmplifyApp()
d := r.Data(nil)
d.SetId(aws.StringValue(app.AppId))
err = r.Delete(d, client)

if err != nil {
log.Printf("[ERROR] %s", err)
sweeperErrs = multierror.Append(sweeperErrs, err)
continue
}
}

return !lastPage
})

if testSweepSkipSweepError(err) {
log.Printf("[WARN] Skipping Amplify Apps sweep for %s: %s", region, err)
return sweeperErrs.ErrorOrNil() // In case we have completed some pages, but had errors
}

if err != nil {
sweeperErrs = multierror.Append(sweeperErrs, fmt.Errorf("error listing Amplify Apps: %w", err))
}

return sweeperErrs.ErrorOrNil()
}

func TestAccAWSAmplifyApp_basic(t *testing.T) {
var app amplify.App
Expand Down

0 comments on commit 6bc6406

Please sign in to comment.