Skip to content

Commit

Permalink
tests/r/waf_byte_match_set: Add sweeper concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed Jun 17, 2021
1 parent 2eb601b commit a19cb6d
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions aws/resource_aws_waf_byte_match_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,27 @@ func init() {

func testSweepWafByteMatchSet(region string) error {
client, err := sharedClientForRegion(region)

if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*AWSClient).wafconn

var sweeperErrs *multierror.Error
conn := client.(*AWSClient).wafconn
sweepResources := make([]*testSweepResource, 0)
var errs *multierror.Error

input := &waf.ListByteMatchSetsInput{}

err = lister.ListByteMatchSetsPages(conn, input, func(page *waf.ListByteMatchSetsOutput, lastPage bool) bool {
err = lister.ListByteMatchSetsPages(conn, input, func(page *waf.ListByteMatchSetsOutput, isLast bool) bool {
if page == nil {
return !lastPage
return !isLast
}

for _, byteMatchSet := range page.ByteMatchSets {
id := aws.StringValue(byteMatchSet.ByteMatchSetId)

r := resourceAwsWafByteMatchSet()
d := r.Data(nil)

id := aws.StringValue(byteMatchSet.ByteMatchSetId)
d.SetId(id)

// Need to Read first to fill in byte_match_tuples attribute
Expand All @@ -56,7 +58,7 @@ func testSweepWafByteMatchSet(region string) error {
if err != nil {
sweeperErr := fmt.Errorf("error reading WAF Byte Match Set (%s): %w", id, err)
log.Printf("[ERROR] %s", sweeperErr)
sweeperErrs = multierror.Append(sweeperErrs, sweeperErr)
errs = multierror.Append(errs, sweeperErr)
continue
}

Expand All @@ -65,29 +67,29 @@ func testSweepWafByteMatchSet(region string) error {
continue
}

err = r.Delete(d, client)

if err != nil {
sweeperErr := fmt.Errorf("error deleting WAF Byte Match Set (%s): %w", id, err)
log.Printf("[ERROR] %s", sweeperErr)
sweeperErrs = multierror.Append(sweeperErrs, sweeperErr)
continue
}
sweepResources = append(sweepResources, NewTestSweepResource(r, d, client))
}

return !lastPage
return !isLast
})

if testSweepSkipSweepError(err) {
log.Printf("[WARN] Skipping WAF Byte Match Set sweep for %s: %s", region, err)
return sweeperErrs.ErrorOrNil() // In case we have completed some pages, but had errors
if err != nil {
errs = multierror.Append(errs, fmt.Errorf("error listing WAF Byte Match Set for %s: %w", region, err))
}

if err != nil {
sweeperErrs = multierror.Append(sweeperErrs, fmt.Errorf("error describing WAF Byte Match Sets: %w", err))
if len(sweepResources) > 0 {
// Any errors didn't prevent gathering some sweeping work, so do it.
if err := testSweepResourceOrchestrator(sweepResources); err != nil {
errs = multierror.Append(errs, fmt.Errorf("error sweeping WAF Byte Match Set for %s: %w", region, err))
}
}

if testSweepSkipSweepError(errs.ErrorOrNil()) {
log.Printf("[WARN] Skipping WAF Byte Match Set sweep for %s: %s", region, errs)
return nil
}

return sweeperErrs.ErrorOrNil()
return errs.ErrorOrNil()
}

func TestAccAWSWafByteMatchSet_basic(t *testing.T) {
Expand Down

0 comments on commit a19cb6d

Please sign in to comment.