providers/aws: Test S3 website removal

This commit is contained in:
Justin Campbell 2015-05-06 08:15:07 -04:00
parent eeb65b8d4c
commit 0b78a71ed5
1 changed files with 23 additions and 8 deletions

View File

@ -38,9 +38,17 @@ func TestAccAWSS3BucketWebsite(t *testing.T) {
resource.TestStep{
Config: testAccAWSS3BucketWebsiteConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("aws_s3_bucket.website"),
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
testAccCheckAWSS3BucketWebsite(
"aws_s3_bucket.website", "index.html", "error.html"),
"aws_s3_bucket.bucket", "index.html", "error.html"),
),
},
resource.TestStep{
Config: testAccAWSS3BucketConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
testAccCheckAWSS3BucketWebsite(
"aws_s3_bucket.bucket", "", ""),
),
},
},
@ -97,8 +105,14 @@ func testAccCheckAWSS3BucketWebsite(n string, indexDoc string, errorDoc string)
})
if err != nil {
if indexDoc == "" {
// If we want to assert that the website is not there, than
// this error is expected
return nil
} else {
return fmt.Errorf("S3BucketWebsite error: %v", err)
}
}
if *out.IndexDocument.Suffix != indexDoc {
return fmt.Errorf("bad: %s", out.IndexDocument)
@ -112,18 +126,19 @@ func testAccCheckAWSS3BucketWebsite(n string, indexDoc string, errorDoc string)
}
}
// These need a bit of randoness as the name can only be used once globally
// These need a bit of randomness as the name can only be used once globally
// within AWS
var d = rand.New(rand.NewSource(time.Now().UnixNano())).Int()
var testAccAWSS3BucketConfig = fmt.Sprintf(`
resource "aws_s3_bucket" "bucket" {
bucket = "tf-test-bucket-%d"
acl = "public-read"
}
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
`, d)
var testAccAWSS3BucketWebsiteConfig = fmt.Sprintf(`
resource "aws_s3_bucket" "website" {
bucket = "tf-test-bucket-website-%d"
resource "aws_s3_bucket" "bucket" {
bucket = "tf-test-bucket-%d"
acl = "public-read"
website {
@ -131,4 +146,4 @@ resource "aws_s3_bucket" "website" {
error_document = "error.html"
}
}
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
`, d)