Merge pull request #4509 from hashicorp/phinze/google-storage-test-collisions
provider/google: enchance storage acctests to avoid collisions
This commit is contained in:
commit
0ee57c2d13
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
||||
|
@ -18,19 +19,22 @@ var roleEntityBasic3_owner = "OWNER:user-yetanotheremail@gmail.com"
|
|||
|
||||
var roleEntityBasic3_reader = "READER:user-yetanotheremail@gmail.com"
|
||||
|
||||
var testAclBucketName = fmt.Sprintf("%s-%d", "tf-test-acl-bucket", genRandInt())
|
||||
func testAclBucketName() string {
|
||||
return fmt.Sprintf("%s-%d", "tf-test-acl-bucket", acctest.RandInt())
|
||||
}
|
||||
|
||||
func TestAccGoogleStorageBucketAcl_basic(t *testing.T) {
|
||||
bucketName := testAclBucketName()
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccGoogleStorageBucketAclDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsAclBasic1,
|
||||
Config: testGoogleStorageBucketsAclBasic1(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageBucketAcl(testAclBucketName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageBucketAcl(testAclBucketName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageBucketAcl(bucketName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageBucketAcl(bucketName, roleEntityBasic2),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -38,33 +42,34 @@ func TestAccGoogleStorageBucketAcl_basic(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccGoogleStorageBucketAcl_upgrade(t *testing.T) {
|
||||
bucketName := testAclBucketName()
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccGoogleStorageBucketAclDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsAclBasic1,
|
||||
Config: testGoogleStorageBucketsAclBasic1(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageBucketAcl(testAclBucketName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageBucketAcl(testAclBucketName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageBucketAcl(bucketName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageBucketAcl(bucketName, roleEntityBasic2),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsAclBasic2,
|
||||
Config: testGoogleStorageBucketsAclBasic2(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageBucketAcl(testAclBucketName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageBucketAcl(testAclBucketName, roleEntityBasic3_owner),
|
||||
testAccCheckGoogleStorageBucketAcl(bucketName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageBucketAcl(bucketName, roleEntityBasic3_owner),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsAclBasicDelete,
|
||||
Config: testGoogleStorageBucketsAclBasicDelete(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageBucketAclDelete(testAclBucketName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageBucketAclDelete(testAclBucketName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageBucketAclDelete(testAclBucketName, roleEntityBasic3_owner),
|
||||
testAccCheckGoogleStorageBucketAclDelete(bucketName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageBucketAclDelete(bucketName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageBucketAclDelete(bucketName, roleEntityBasic3_owner),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -72,33 +77,34 @@ func TestAccGoogleStorageBucketAcl_upgrade(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccGoogleStorageBucketAcl_downgrade(t *testing.T) {
|
||||
bucketName := testAclBucketName()
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccGoogleStorageBucketAclDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsAclBasic2,
|
||||
Config: testGoogleStorageBucketsAclBasic2(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageBucketAcl(testAclBucketName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageBucketAcl(testAclBucketName, roleEntityBasic3_owner),
|
||||
testAccCheckGoogleStorageBucketAcl(bucketName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageBucketAcl(bucketName, roleEntityBasic3_owner),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsAclBasic3,
|
||||
Config: testGoogleStorageBucketsAclBasic3(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageBucketAcl(testAclBucketName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageBucketAcl(testAclBucketName, roleEntityBasic3_reader),
|
||||
testAccCheckGoogleStorageBucketAcl(bucketName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageBucketAcl(bucketName, roleEntityBasic3_reader),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsAclBasicDelete,
|
||||
Config: testGoogleStorageBucketsAclBasicDelete(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageBucketAclDelete(testAclBucketName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageBucketAclDelete(testAclBucketName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageBucketAclDelete(testAclBucketName, roleEntityBasic3_owner),
|
||||
testAccCheckGoogleStorageBucketAclDelete(bucketName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageBucketAclDelete(bucketName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageBucketAclDelete(bucketName, roleEntityBasic3_owner),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -112,7 +118,7 @@ func TestAccGoogleStorageBucketAcl_predefined(t *testing.T) {
|
|||
CheckDestroy: testAccGoogleStorageBucketAclDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsAclPredefined,
|
||||
Config: testGoogleStorageBucketsAclPredefined(bucketName),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -172,7 +178,8 @@ func testAccGoogleStorageBucketAclDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var testGoogleStorageBucketsAclBasic1 = fmt.Sprintf(`
|
||||
func testGoogleStorageBucketsAclBasic1(bucketName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -181,9 +188,11 @@ resource "google_storage_bucket_acl" "acl" {
|
|||
bucket = "${google_storage_bucket.bucket.name}"
|
||||
role_entity = ["%s", "%s"]
|
||||
}
|
||||
`, testAclBucketName, roleEntityBasic1, roleEntityBasic2)
|
||||
`, bucketName, roleEntityBasic1, roleEntityBasic2)
|
||||
}
|
||||
|
||||
var testGoogleStorageBucketsAclBasic2 = fmt.Sprintf(`
|
||||
func testGoogleStorageBucketsAclBasic2(bucketName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -192,9 +201,11 @@ resource "google_storage_bucket_acl" "acl" {
|
|||
bucket = "${google_storage_bucket.bucket.name}"
|
||||
role_entity = ["%s", "%s"]
|
||||
}
|
||||
`, testAclBucketName, roleEntityBasic2, roleEntityBasic3_owner)
|
||||
`, bucketName, roleEntityBasic2, roleEntityBasic3_owner)
|
||||
}
|
||||
|
||||
var testGoogleStorageBucketsAclBasicDelete = fmt.Sprintf(`
|
||||
func testGoogleStorageBucketsAclBasicDelete(bucketName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -203,9 +214,11 @@ resource "google_storage_bucket_acl" "acl" {
|
|||
bucket = "${google_storage_bucket.bucket.name}"
|
||||
role_entity = []
|
||||
}
|
||||
`, testAclBucketName)
|
||||
`, bucketName)
|
||||
}
|
||||
|
||||
var testGoogleStorageBucketsAclBasic3 = fmt.Sprintf(`
|
||||
func testGoogleStorageBucketsAclBasic3(bucketName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -214,9 +227,11 @@ resource "google_storage_bucket_acl" "acl" {
|
|||
bucket = "${google_storage_bucket.bucket.name}"
|
||||
role_entity = ["%s", "%s"]
|
||||
}
|
||||
`, testAclBucketName, roleEntityBasic2, roleEntityBasic3_reader)
|
||||
`, bucketName, roleEntityBasic2, roleEntityBasic3_reader)
|
||||
}
|
||||
|
||||
var testGoogleStorageBucketsAclPredefined = fmt.Sprintf(`
|
||||
func testGoogleStorageBucketsAclPredefined(bucketName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -226,4 +241,5 @@ resource "google_storage_bucket_acl" "acl" {
|
|||
predefined_acl = "projectPrivate"
|
||||
default_acl = "projectPrivate"
|
||||
}
|
||||
`, testAclBucketName)
|
||||
`, bucketName)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
||||
|
@ -13,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func TestAccStorage_basic(t *testing.T) {
|
||||
var bucketName string
|
||||
bucketName := fmt.Sprintf("tf-test-acl-bucket-%d", acctest.RandInt())
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -21,10 +22,10 @@ func TestAccStorage_basic(t *testing.T) {
|
|||
CheckDestroy: testAccGoogleStorageDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsReaderDefaults,
|
||||
Config: testGoogleStorageBucketsReaderDefaults(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckCloudStorageBucketExists(
|
||||
"google_storage_bucket.bucket", &bucketName),
|
||||
"google_storage_bucket.bucket", bucketName),
|
||||
resource.TestCheckResourceAttr(
|
||||
"google_storage_bucket.bucket", "location", "US"),
|
||||
resource.TestCheckResourceAttr(
|
||||
|
@ -36,7 +37,7 @@ func TestAccStorage_basic(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccStorageCustomAttributes(t *testing.T) {
|
||||
var bucketName string
|
||||
bucketName := fmt.Sprintf("tf-test-acl-bucket-%d", acctest.RandInt())
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -44,10 +45,10 @@ func TestAccStorageCustomAttributes(t *testing.T) {
|
|||
CheckDestroy: testAccGoogleStorageDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsReaderCustomAttributes,
|
||||
Config: testGoogleStorageBucketsReaderCustomAttributes(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckCloudStorageBucketExists(
|
||||
"google_storage_bucket.bucket", &bucketName),
|
||||
"google_storage_bucket.bucket", bucketName),
|
||||
resource.TestCheckResourceAttr(
|
||||
"google_storage_bucket.bucket", "location", "EU"),
|
||||
resource.TestCheckResourceAttr(
|
||||
|
@ -59,7 +60,7 @@ func TestAccStorageCustomAttributes(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccStorageBucketUpdate(t *testing.T) {
|
||||
var bucketName string
|
||||
bucketName := fmt.Sprintf("tf-test-acl-bucket-%d", acctest.RandInt())
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -67,10 +68,10 @@ func TestAccStorageBucketUpdate(t *testing.T) {
|
|||
CheckDestroy: testAccGoogleStorageDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsReaderDefaults,
|
||||
Config: testGoogleStorageBucketsReaderDefaults(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckCloudStorageBucketExists(
|
||||
"google_storage_bucket.bucket", &bucketName),
|
||||
"google_storage_bucket.bucket", bucketName),
|
||||
resource.TestCheckResourceAttr(
|
||||
"google_storage_bucket.bucket", "location", "US"),
|
||||
resource.TestCheckResourceAttr(
|
||||
|
@ -78,10 +79,10 @@ func TestAccStorageBucketUpdate(t *testing.T) {
|
|||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsReaderCustomAttributes,
|
||||
Config: testGoogleStorageBucketsReaderCustomAttributes(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckCloudStorageBucketExists(
|
||||
"google_storage_bucket.bucket", &bucketName),
|
||||
"google_storage_bucket.bucket", bucketName),
|
||||
resource.TestCheckResourceAttr(
|
||||
"google_storage_bucket.bucket", "predefined_acl", "publicReadWrite"),
|
||||
resource.TestCheckResourceAttr(
|
||||
|
@ -95,7 +96,7 @@ func TestAccStorageBucketUpdate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccStorageForceDestroy(t *testing.T) {
|
||||
var bucketName string
|
||||
bucketName := fmt.Sprintf("tf-test-acl-bucket-%d", acctest.RandInt())
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -103,29 +104,29 @@ func TestAccStorageForceDestroy(t *testing.T) {
|
|||
CheckDestroy: testAccGoogleStorageDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsReaderCustomAttributes,
|
||||
Config: testGoogleStorageBucketsReaderCustomAttributes(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckCloudStorageBucketExists(
|
||||
"google_storage_bucket.bucket", &bucketName),
|
||||
"google_storage_bucket.bucket", bucketName),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageBucketsReaderCustomAttributes,
|
||||
Config: testGoogleStorageBucketsReaderCustomAttributes(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckCloudStorageBucketPutItem(&bucketName),
|
||||
testAccCheckCloudStorageBucketPutItem(bucketName),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: "",
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckCloudStorageBucketMissing(&bucketName),
|
||||
testAccCheckCloudStorageBucketMissing(bucketName),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckCloudStorageBucketExists(n string, bucketName *string) resource.TestCheckFunc {
|
||||
func testAccCheckCloudStorageBucketExists(n string, bucketName string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[n]
|
||||
if !ok {
|
||||
|
@ -147,12 +148,14 @@ func testAccCheckCloudStorageBucketExists(n string, bucketName *string) resource
|
|||
return fmt.Errorf("Bucket not found")
|
||||
}
|
||||
|
||||
*bucketName = found.Name
|
||||
if found.Name != bucketName {
|
||||
return fmt.Errorf("expected name %s, got %s", bucketName, found.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testAccCheckCloudStorageBucketPutItem(bucketName *string) resource.TestCheckFunc {
|
||||
func testAccCheckCloudStorageBucketPutItem(bucketName string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
config := testAccProvider.Meta().(*Config)
|
||||
|
||||
|
@ -161,7 +164,7 @@ func testAccCheckCloudStorageBucketPutItem(bucketName *string) resource.TestChec
|
|||
object := &storage.Object{Name: "bucketDestroyTestFile"}
|
||||
|
||||
// This needs to use Media(io.Reader) call, otherwise it does not go to /upload API and fails
|
||||
if res, err := config.clientStorage.Objects.Insert(*bucketName, object).Media(dataReader).Do(); err == nil {
|
||||
if res, err := config.clientStorage.Objects.Insert(bucketName, object).Media(dataReader).Do(); err == nil {
|
||||
fmt.Printf("Created object %v at location %v\n\n", res.Name, res.SelfLink)
|
||||
} else {
|
||||
return fmt.Errorf("Objects.Insert failed: %v", err)
|
||||
|
@ -171,20 +174,20 @@ func testAccCheckCloudStorageBucketPutItem(bucketName *string) resource.TestChec
|
|||
}
|
||||
}
|
||||
|
||||
func testAccCheckCloudStorageBucketMissing(bucketName *string) resource.TestCheckFunc {
|
||||
func testAccCheckCloudStorageBucketMissing(bucketName string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
config := testAccProvider.Meta().(*Config)
|
||||
|
||||
_, err := config.clientStorage.Buckets.Get(*bucketName).Do()
|
||||
_, err := config.clientStorage.Buckets.Get(bucketName).Do()
|
||||
if err == nil {
|
||||
return fmt.Errorf("Found %s", *bucketName)
|
||||
return fmt.Errorf("Found %s", bucketName)
|
||||
}
|
||||
|
||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
||||
return nil
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,19 +208,21 @@ func testAccGoogleStorageDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var randInt = genRandInt()
|
||||
|
||||
var testGoogleStorageBucketsReaderDefaults = fmt.Sprintf(`
|
||||
func testGoogleStorageBucketsReaderDefaults(bucketName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "tf-test-bucket-%d"
|
||||
name = "%s"
|
||||
}
|
||||
`, bucketName)
|
||||
}
|
||||
`, randInt)
|
||||
|
||||
var testGoogleStorageBucketsReaderCustomAttributes = fmt.Sprintf(`
|
||||
func testGoogleStorageBucketsReaderCustomAttributes(bucketName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "tf-test-bucket-%d"
|
||||
name = "%s"
|
||||
predefined_acl = "publicReadWrite"
|
||||
location = "EU"
|
||||
force_destroy = "true"
|
||||
}
|
||||
`, randInt)
|
||||
`, bucketName)
|
||||
}
|
||||
|
|
|
@ -14,10 +14,15 @@ import (
|
|||
)
|
||||
|
||||
var tfObjectAcl, errObjectAcl = ioutil.TempFile("", "tf-gce-test")
|
||||
var testAclObjectName = fmt.Sprintf("%s-%d", "tf-test-acl-object",
|
||||
|
||||
func testAclObjectName() string {
|
||||
return fmt.Sprintf("%s-%d", "tf-test-acl-object",
|
||||
rand.New(rand.NewSource(time.Now().UnixNano())).Int())
|
||||
}
|
||||
|
||||
func TestAccGoogleStorageObjectAcl_basic(t *testing.T) {
|
||||
bucketName := testAclBucketName()
|
||||
objectName := testAclObjectName()
|
||||
objectData := []byte("data data data")
|
||||
ioutil.WriteFile(tfObjectAcl.Name(), objectData, 0644)
|
||||
resource.Test(t, resource.TestCase{
|
||||
|
@ -31,12 +36,12 @@ func TestAccGoogleStorageObjectAcl_basic(t *testing.T) {
|
|||
CheckDestroy: testAccGoogleStorageObjectAclDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageObjectsAclBasic1,
|
||||
Config: testGoogleStorageObjectsAclBasic1(bucketName, objectName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageObjectAcl(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageObjectAcl(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageObjectAcl(bucketName,
|
||||
objectName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageObjectAcl(bucketName,
|
||||
objectName, roleEntityBasic2),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -44,6 +49,8 @@ func TestAccGoogleStorageObjectAcl_basic(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccGoogleStorageObjectAcl_upgrade(t *testing.T) {
|
||||
bucketName := testAclBucketName()
|
||||
objectName := testAclObjectName()
|
||||
objectData := []byte("data data data")
|
||||
ioutil.WriteFile(tfObjectAcl.Name(), objectData, 0644)
|
||||
resource.Test(t, resource.TestCase{
|
||||
|
@ -57,34 +64,34 @@ func TestAccGoogleStorageObjectAcl_upgrade(t *testing.T) {
|
|||
CheckDestroy: testAccGoogleStorageObjectAclDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageObjectsAclBasic1,
|
||||
Config: testGoogleStorageObjectsAclBasic1(bucketName, objectName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageObjectAcl(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageObjectAcl(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageObjectAcl(bucketName,
|
||||
objectName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageObjectAcl(bucketName,
|
||||
objectName, roleEntityBasic2),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageObjectsAclBasic2,
|
||||
Config: testGoogleStorageObjectsAclBasic2(bucketName, objectName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageObjectAcl(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageObjectAcl(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic3_owner),
|
||||
testAccCheckGoogleStorageObjectAcl(bucketName,
|
||||
objectName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageObjectAcl(bucketName,
|
||||
objectName, roleEntityBasic3_owner),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageObjectsAclBasicDelete,
|
||||
Config: testGoogleStorageObjectsAclBasicDelete(bucketName, objectName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageObjectAclDelete(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageObjectAclDelete(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageObjectAclDelete(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic3_reader),
|
||||
testAccCheckGoogleStorageObjectAclDelete(bucketName,
|
||||
objectName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageObjectAclDelete(bucketName,
|
||||
objectName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageObjectAclDelete(bucketName,
|
||||
objectName, roleEntityBasic3_reader),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -92,6 +99,8 @@ func TestAccGoogleStorageObjectAcl_upgrade(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccGoogleStorageObjectAcl_downgrade(t *testing.T) {
|
||||
bucketName := testAclBucketName()
|
||||
objectName := testAclObjectName()
|
||||
objectData := []byte("data data data")
|
||||
ioutil.WriteFile(tfObjectAcl.Name(), objectData, 0644)
|
||||
resource.Test(t, resource.TestCase{
|
||||
|
@ -105,34 +114,34 @@ func TestAccGoogleStorageObjectAcl_downgrade(t *testing.T) {
|
|||
CheckDestroy: testAccGoogleStorageObjectAclDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageObjectsAclBasic2,
|
||||
Config: testGoogleStorageObjectsAclBasic2(bucketName, objectName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageObjectAcl(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageObjectAcl(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic3_owner),
|
||||
testAccCheckGoogleStorageObjectAcl(bucketName,
|
||||
objectName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageObjectAcl(bucketName,
|
||||
objectName, roleEntityBasic3_owner),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageObjectsAclBasic3,
|
||||
Config: testGoogleStorageObjectsAclBasic3(bucketName, objectName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageObjectAcl(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageObjectAcl(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic3_reader),
|
||||
testAccCheckGoogleStorageObjectAcl(bucketName,
|
||||
objectName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageObjectAcl(bucketName,
|
||||
objectName, roleEntityBasic3_reader),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageObjectsAclBasicDelete,
|
||||
Config: testGoogleStorageObjectsAclBasicDelete(bucketName, objectName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleStorageObjectAclDelete(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageObjectAclDelete(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageObjectAclDelete(testAclBucketName,
|
||||
testAclObjectName, roleEntityBasic3_reader),
|
||||
testAccCheckGoogleStorageObjectAclDelete(bucketName,
|
||||
objectName, roleEntityBasic1),
|
||||
testAccCheckGoogleStorageObjectAclDelete(bucketName,
|
||||
objectName, roleEntityBasic2),
|
||||
testAccCheckGoogleStorageObjectAclDelete(bucketName,
|
||||
objectName, roleEntityBasic3_reader),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -140,6 +149,8 @@ func TestAccGoogleStorageObjectAcl_downgrade(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccGoogleStorageObjectAcl_predefined(t *testing.T) {
|
||||
bucketName := testAclBucketName()
|
||||
objectName := testAclObjectName()
|
||||
objectData := []byte("data data data")
|
||||
ioutil.WriteFile(tfObjectAcl.Name(), objectData, 0644)
|
||||
resource.Test(t, resource.TestCase{
|
||||
|
@ -153,7 +164,7 @@ func TestAccGoogleStorageObjectAcl_predefined(t *testing.T) {
|
|||
CheckDestroy: testAccGoogleStorageObjectAclDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testGoogleStorageObjectsAclPredefined,
|
||||
Config: testGoogleStorageObjectsAclPredefined(bucketName, objectName),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -216,7 +227,8 @@ func testAccGoogleStorageObjectAclDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var testGoogleStorageObjectsAclBasicDelete = fmt.Sprintf(`
|
||||
func testGoogleStorageObjectsAclBasicDelete(bucketName string, objectName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -232,9 +244,11 @@ resource "google_storage_object_acl" "acl" {
|
|||
bucket = "${google_storage_bucket.bucket.name}"
|
||||
role_entity = []
|
||||
}
|
||||
`, testAclBucketName, testAclObjectName, tfObjectAcl.Name())
|
||||
`, bucketName, objectName, tfObjectAcl.Name())
|
||||
}
|
||||
|
||||
var testGoogleStorageObjectsAclBasic1 = fmt.Sprintf(`
|
||||
func testGoogleStorageObjectsAclBasic1(bucketName string, objectName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -250,10 +264,12 @@ resource "google_storage_object_acl" "acl" {
|
|||
bucket = "${google_storage_bucket.bucket.name}"
|
||||
role_entity = ["%s", "%s"]
|
||||
}
|
||||
`, testAclBucketName, testAclObjectName, tfObjectAcl.Name(),
|
||||
`, bucketName, objectName, tfObjectAcl.Name(),
|
||||
roleEntityBasic1, roleEntityBasic2)
|
||||
}
|
||||
|
||||
var testGoogleStorageObjectsAclBasic2 = fmt.Sprintf(`
|
||||
func testGoogleStorageObjectsAclBasic2(bucketName string, objectName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -269,10 +285,12 @@ resource "google_storage_object_acl" "acl" {
|
|||
bucket = "${google_storage_bucket.bucket.name}"
|
||||
role_entity = ["%s", "%s"]
|
||||
}
|
||||
`, testAclBucketName, testAclObjectName, tfObjectAcl.Name(),
|
||||
`, bucketName, objectName, tfObjectAcl.Name(),
|
||||
roleEntityBasic2, roleEntityBasic3_owner)
|
||||
}
|
||||
|
||||
var testGoogleStorageObjectsAclBasic3 = fmt.Sprintf(`
|
||||
func testGoogleStorageObjectsAclBasic3(bucketName string, objectName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -288,10 +306,12 @@ resource "google_storage_object_acl" "acl" {
|
|||
bucket = "${google_storage_bucket.bucket.name}"
|
||||
role_entity = ["%s", "%s"]
|
||||
}
|
||||
`, testAclBucketName, testAclObjectName, tfObjectAcl.Name(),
|
||||
`, bucketName, objectName, tfObjectAcl.Name(),
|
||||
roleEntityBasic2, roleEntityBasic3_reader)
|
||||
}
|
||||
|
||||
var testGoogleStorageObjectsAclPredefined = fmt.Sprintf(`
|
||||
func testGoogleStorageObjectsAclPredefined(bucketName string, objectName string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "%s"
|
||||
}
|
||||
|
@ -307,4 +327,5 @@ resource "google_storage_object_acl" "acl" {
|
|||
bucket = "${google_storage_bucket.bucket.name}"
|
||||
predefined_acl = "projectPrivate"
|
||||
}
|
||||
`, testAclBucketName, testAclObjectName, tfObjectAcl.Name())
|
||||
`, bucketName, objectName, tfObjectAcl.Name())
|
||||
}
|
||||
|
|
|
@ -8,6 +8,12 @@ import (
|
|||
// Helpers for generating random tidbits for use in identifiers to prevent
|
||||
// collisions in acceptance tests.
|
||||
|
||||
// RandInt generates a random integer
|
||||
func RandInt() int {
|
||||
reseed()
|
||||
return rand.New(rand.NewSource(time.Now().UnixNano())).Int()
|
||||
}
|
||||
|
||||
// RandString generates a random alphanumeric string of the length specified
|
||||
func RandString(strlen int) string {
|
||||
return RandStringFromCharSet(strlen, CharSetAlphaNum)
|
||||
|
@ -16,7 +22,7 @@ func RandString(strlen int) string {
|
|||
// RandStringFromCharSet generates a random string by selecting characters from
|
||||
// the charset provided
|
||||
func RandStringFromCharSet(strlen int, charSet string) string {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
reseed()
|
||||
result := make([]byte, strlen)
|
||||
for i := 0; i < strlen; i++ {
|
||||
result[i] = charSet[rand.Intn(len(charSet))]
|
||||
|
@ -24,6 +30,11 @@ func RandStringFromCharSet(strlen int, charSet string) string {
|
|||
return string(result)
|
||||
}
|
||||
|
||||
// Seeds random with current timestamp
|
||||
func reseed() {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
}
|
||||
|
||||
const (
|
||||
// CharSetAlphaNum is the alphanumeric character set for use with
|
||||
// RandStringFromCharSet
|
||||
|
|
Loading…
Reference in New Issue