Skip to content

Commit

Permalink
updated tests to also test update acl
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasB committed Jun 26, 2019
1 parent 8827563 commit df572a9
Showing 1 changed file with 50 additions and 29 deletions.
79 changes: 50 additions & 29 deletions scaleway/resource_storage_object_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,26 @@ func init() {
})
}

func testSweepStorageObjectBucket(region string) error {
s3client, err := sharedS3ClientForRegion(region)
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}

listBucketResponse, err := s3client.ListBuckets(&s3.ListBucketsInput{})
if err != nil {
return fmt.Errorf("couldn't list buckets: %s", err)
}

for _, bucket := range listBucketResponse.Buckets {
l.Debugf("Deleting %q bucket", *bucket.Name)
if strings.HasPrefix(*bucket.Name, "terraform-test") {
_, err := s3client.DeleteBucket(&s3.DeleteBucketInput{
Bucket: bucket.Name,
})
if err != nil {
return fmt.Errorf("Error deleting bucket in Sweeper: %s", err)
}
}

}
// Test data
var (
testBucketName = fmt.Sprintf("terraform-test-%d", time.Now().Unix())
testBucketACL = "private"
testBucketUpdatedACL = "public-read"
)

return nil
// Test configs
var testAccCheckScalewayStorageObjectBucket = fmt.Sprintf(`
resource "scaleway_storage_object_bucket" "base" {
name = "%s"
}
`, testBucketName)

var testAccCheckScalewayStorageObjectBucketUpdate = fmt.Sprintf(`
resource "scaleway_storage_object_bucket" "base" {
name = "%s"
acl = "%s"
}
`, testBucketName, testBucketUpdatedACL)

func TestAccScalewayStorageObjectBucket(t *testing.T) {
resource.Test(t, resource.TestCase{
Expand All @@ -57,6 +50,14 @@ func TestAccScalewayStorageObjectBucket(t *testing.T) {
Config: testAccCheckScalewayStorageObjectBucket,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("scaleway_storage_object_bucket.base", "name", testBucketName),
resource.TestCheckResourceAttr("scaleway_storage_object_bucket.base", "acl", testBucketACL),
),
},
{
Config: testAccCheckScalewayStorageObjectBucketUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("scaleway_storage_object_bucket.base", "name", testBucketName),
resource.TestCheckResourceAttr("scaleway_storage_object_bucket.base", "acl", testBucketUpdatedACL),
),
},
},
Expand Down Expand Up @@ -90,10 +91,30 @@ func testAccCheckScalewayStorageObjectBucketDestroy(s *terraform.State) error {
return nil
}

var testBucketName = fmt.Sprintf("terraform-test-%d", time.Now().Unix())
func testSweepStorageObjectBucket(region string) error {
s3client, err := sharedS3ClientForRegion(region)
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}

listBucketResponse, err := s3client.ListBuckets(&s3.ListBucketsInput{})
if err != nil {
return fmt.Errorf("couldn't list buckets: %s", err)
}

for _, bucket := range listBucketResponse.Buckets {
l.Debugf("Deleting %q bucket", *bucket.Name)
if strings.HasPrefix(*bucket.Name, "terraform-test") {
_, err := s3client.DeleteBucket(&s3.DeleteBucketInput{
Bucket: bucket.Name,
})
if err != nil {
return fmt.Errorf("Error deleting bucket in Sweeper: %s", err)
}
}

}

return nil

var testAccCheckScalewayStorageObjectBucket = fmt.Sprintf(`
resource "scaleway_storage_object_bucket" "base" {
name = "%s"
}
`, testBucketName)

0 comments on commit df572a9

Please sign in to comment.