provider/aws: S3 bucket test that should fail
This commit is contained in:
parent
c10c47623e
commit
83827a5cb7
|
@ -134,6 +134,26 @@ func TestAccAWSS3Bucket_WebsiteRedirect(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test TestAccAWSS3Bucket_shouldFailNotFound is designed to fail with a "plan
|
||||||
|
// not empty" error in Terraform, to check against regresssions.
|
||||||
|
// See https://github.com/hashicorp/terraform/pull/2925
|
||||||
|
func TestAccAWSS3Bucket_shouldFailNotFound(t *testing.T) {
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckAWSS3BucketDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSS3BucketDestroyedConfig,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
|
||||||
|
testAccCheckAWSS3DestroyBucket("aws_s3_bucket.bucket"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckAWSS3BucketDestroy(s *terraform.State) error {
|
func testAccCheckAWSS3BucketDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).s3conn
|
conn := testAccProvider.Meta().(*AWSClient).s3conn
|
||||||
|
|
||||||
|
@ -174,6 +194,29 @@ func testAccCheckAWSS3BucketExists(n string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckAWSS3DestroyBucket(n string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", n)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rs.Primary.ID == "" {
|
||||||
|
return fmt.Errorf("No S3 Bucket ID is set")
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*AWSClient).s3conn
|
||||||
|
_, err := conn.DeleteBucket(&s3.DeleteBucketInput{
|
||||||
|
Bucket: aws.String(rs.Primary.ID),
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error destroying Bucket (%s) in testAccCheckAWSS3DestroyBucket: %s", rs.Primary.ID, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckAWSS3BucketPolicy(n string, policy string) resource.TestCheckFunc {
|
func testAccCheckAWSS3BucketPolicy(n string, policy string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, _ := s.RootModule().Resources[n]
|
rs, _ := s.RootModule().Resources[n]
|
||||||
|
@ -321,3 +364,11 @@ resource "aws_s3_bucket" "bucket" {
|
||||||
policy = %s
|
policy = %s
|
||||||
}
|
}
|
||||||
`, randInt, strconv.Quote(testAccAWSS3BucketPolicy))
|
`, randInt, strconv.Quote(testAccAWSS3BucketPolicy))
|
||||||
|
|
||||||
|
var destroyedName = fmt.Sprintf("tf-test-bucket-%d", randInt)
|
||||||
|
var testAccAWSS3BucketDestroyedConfig = fmt.Sprintf(`
|
||||||
|
resource "aws_s3_bucket" "bucket" {
|
||||||
|
bucket = "%s"
|
||||||
|
acl = "public-read"
|
||||||
|
}
|
||||||
|
`, destroyedName)
|
||||||
|
|
Loading…
Reference in New Issue