provider/aws: Fix s3_bucket test for empty policy

This commit is contained in:
Radek Simko 2016-09-18 20:57:50 +01:00
parent 95c28aca4f
commit 1c3258d629
No known key found for this signature in database
GPG Key ID: 6823F3DCCE01BB19
1 changed files with 8 additions and 2 deletions

View File

@ -645,14 +645,20 @@ func testAccCheckAWSS3BucketPolicy(n string, policy string) resource.TestCheckFu
Bucket: aws.String(rs.Primary.ID), Bucket: aws.String(rs.Primary.ID),
}) })
if err != nil { if policy == "" {
if policy == "" { if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "NoSuchBucketPolicy" {
// expected // expected
return nil return nil
}
if err == nil {
return fmt.Errorf("Expected no policy, got: %#v", *out.Policy)
} else { } else {
return fmt.Errorf("GetBucketPolicy error: %v, expected %s", err, policy) return fmt.Errorf("GetBucketPolicy error: %v, expected %s", err, policy)
} }
} }
if err != nil {
return fmt.Errorf("GetBucketPolicy error: %v, expected %s", err, policy)
}
if v := out.Policy; v == nil { if v := out.Policy; v == nil {
if policy != "" { if policy != "" {