Skip to content

Commit

Permalink
Improve testAccCheckAWSS3BucketReplicationRules to use specifc provider.
Browse files Browse the repository at this point in the history
This was done in the spirit of current
testAccCheckAWSS3BucketExistsWithProvider. Previous provider for loop
has been deprecated as of late.
  • Loading branch information
modax committed Feb 20, 2018
1 parent 2c8906e commit 2b643af
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions aws/resource_aws_s3_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ func TestAccAWSS3Bucket_Replication(t *testing.T) {
testAccCheckAWSS3BucketExistsWithProvider("aws_s3_bucket.destination", testAccAwsRegionProviderFunc("eu-west-1", &providers)),
testAccCheckAWSS3BucketReplicationRules(
"aws_s3_bucket.bucket",
&providers,
testAccAwsRegionProviderFunc("us-west-2", &providers),
[]*s3.ReplicationRule{
{
ID: aws.String("foobar"),
Expand All @@ -796,7 +796,7 @@ func TestAccAWSS3Bucket_Replication(t *testing.T) {
resource.TestCheckResourceAttr("aws_s3_bucket.bucket", "replication_configuration.0.rules.#", "1"),
testAccCheckAWSS3BucketReplicationRules(
"aws_s3_bucket.bucket",
&providers,
testAccAwsRegionProviderFunc("us-west-2", &providers),
[]*s3.ReplicationRule{
{
ID: aws.String("foobar"),
Expand Down Expand Up @@ -1243,7 +1243,7 @@ func testAccCheckAWSS3BucketLogging(n, b, p string) resource.TestCheckFunc {
}
}

func testAccCheckAWSS3BucketReplicationRules(n string, providers *[]*schema.Provider, rules []*s3.ReplicationRule) resource.TestCheckFunc {
func testAccCheckAWSS3BucketReplicationRules(n string, providerF func() *schema.Provider, rules []*s3.ReplicationRule) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, _ := s.RootModule().Resources[n]
for _, rule := range rules {
Expand All @@ -1256,29 +1256,27 @@ func testAccCheckAWSS3BucketReplicationRules(n string, providers *[]*schema.Prov
}
}
}
for _, provider := range *providers {
// Ignore if Meta is empty, this can happen for validation providers
if provider.Meta() == nil {
continue
}

conn := provider.Meta().(*AWSClient).s3conn
out, err := conn.GetBucketReplication(&s3.GetBucketReplicationInput{
Bucket: aws.String(rs.Primary.ID),
})
if err != nil {
if rules == nil {
return nil
}
return fmt.Errorf("GetReplicationConfiguration error: %v", err)
provider := providerF()

conn := provider.Meta().(*AWSClient).s3conn
out, err := conn.GetBucketReplication(&s3.GetBucketReplicationInput{
Bucket: aws.String(rs.Primary.ID),
})
if err != nil {
if isAWSErr(err, s3.ErrCodeNoSuchBucket, "") {
return fmt.Errorf("S3 bucket not found")
}
if !reflect.DeepEqual(out.ReplicationConfiguration.Rules, rules) {
return fmt.Errorf("bad replication rules, expected: %v, got %v", rules, out.ReplicationConfiguration.Rules)
if rules == nil {
return nil
}

return nil
return fmt.Errorf("GetReplicationConfiguration error: %v", err)
}
if !reflect.DeepEqual(out.ReplicationConfiguration.Rules, rules) {
return fmt.Errorf("bad replication rules, expected: %v, got %v", rules, out.ReplicationConfiguration.Rules)
}
return fmt.Errorf("Bucket not found")

return nil
}
}

Expand Down

0 comments on commit 2b643af

Please sign in to comment.