Skip to content

Commit

Permalink
add proper timeout duration for s3bucket wait and add acceptance tests
Browse files Browse the repository at this point in the history
issue: [hashicorp#877]
  • Loading branch information
xchapter7x committed Aug 10, 2017
1 parent 9881a85 commit 8f29fcf
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func resourceAwsS3BucketCreate(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return fmt.Errorf("Error waiting for S3 Bucket creation: ", err)
}
case <-time.After(60):
case <-time.After(time.Duration(60) * time.Second):
return errors.New("S3 bucket creation timed out")
}
return resourceAwsS3BucketUpdate(d, meta)
Expand Down
90 changes: 90 additions & 0 deletions aws/resource_aws_s3_bucket_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package aws

import (
"bytes"
"encoding/json"
"fmt"
"html/template"
"reflect"
"regexp"
"strconv"
Expand Down Expand Up @@ -56,6 +58,26 @@ func TestAccAWSS3Bucket_basic(t *testing.T) {
})
}

func TestAccAWSS3Bucket_withTags(t *testing.T) {
for i := 0; i < 10; i++ {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
/*
IDRefreshName: "aws_s3_bucket.bucket",
IDRefreshIgnore: []string{"force_destroy"},
*/
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSS3BucketDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSS3MultiBucketConfigWithTags(rInt),
},
},
})
}
}

func TestAccAWSS3Bucket_namePrefix(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -1174,6 +1196,74 @@ resource "aws_s3_bucket" "bucket" {
`, randInt)
}

func testAccAWSS3MultiBucketConfigWithTags(randInt int) string {
t := template.Must(template.New("t1").
Parse(`
resource "aws_s3_bucket" "bucket1" {
bucket = "tf-test-bucket-1-{{.GUID}}"
acl = "private"
force_destroy = true
tags {
Name = "tf-test-bucket-1-{{.GUID}}"
Environment = "{{.GUID}}"
}
}
resource "aws_s3_bucket" "bucket2" {
bucket = "tf-test-bucket-2-{{.GUID}}"
acl = "private"
force_destroy = true
tags {
Name = "tf-test-bucket-2-{{.GUID}}"
Environment = "{{.GUID}}"
}
}
resource "aws_s3_bucket" "bucket3" {
bucket = "tf-test-bucket-3-{{.GUID}}"
acl = "private"
force_destroy = true
tags {
Name = "tf-test-bucket-3-{{.GUID}}"
Environment = "{{.GUID}}"
}
}
resource "aws_s3_bucket" "bucket4" {
bucket = "tf-test-bucket-4-{{.GUID}}"
acl = "private"
force_destroy = true
tags {
Name = "tf-test-bucket-4-{{.GUID}}"
Environment = "{{.GUID}}"
}
}
resource "aws_s3_bucket" "bucket5" {
bucket = "tf-test-bucket-5-{{.GUID}}"
acl = "private"
force_destroy = true
tags {
Name = "tf-test-bucket-5-{{.GUID}}"
Environment = "{{.GUID}}"
}
}
resource "aws_s3_bucket" "bucket6" {
bucket = "tf-test-bucket-6-{{.GUID}}"
acl = "private"
force_destroy = true
tags {
Name = "tf-test-bucket-6-{{.GUID}}"
Environment = "{{.GUID}}"
}
}
`))
var doc bytes.Buffer
t.Execute(&doc, struct{ GUID int }{GUID: randInt})
return doc.String()
}

func testAccAWSS3BucketConfigWithRegion(randInt int) string {
return fmt.Sprintf(`
provider "aws" {
Expand Down

0 comments on commit 8f29fcf

Please sign in to comment.