forked from digitalocean/terraform-provider-digitalocean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasource_digitalocean_spaces_buckets_test.go
66 lines (58 loc) · 2.23 KB
/
datasource_digitalocean_spaces_buckets_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package digitalocean
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccDataSourceDigitalOceanSpacesBuckets_Basic(t *testing.T) {
bucketName1 := testAccBucketName(acctest.RandInt())
bucketRegion1 := "nyc3"
bucketName2 := testAccBucketName(acctest.RandInt())
bucketRegion2 := "ams3"
bucketsConfig := fmt.Sprintf(`
resource "digitalocean_spaces_bucket" "bucket1" {
name = "%s"
region = "%s"
}
resource "digitalocean_spaces_bucket" "bucket2" {
name = "%s"
region = "%s"
}
`, bucketName1, bucketRegion1, bucketName2, bucketRegion2)
datasourceConfig := fmt.Sprintf(`
data "digitalocean_spaces_buckets" "result" {
filter {
key = "name"
values = ["%s"]
}
}
`, bucketName1)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckDigitalOceanBucketDestroy,
Steps: []resource.TestStep{
{
Config: bucketsConfig,
},
{
Config: bucketsConfig + datasourceConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.digitalocean_spaces_buckets.result", "buckets.#", "1"),
resource.TestCheckResourceAttr("data.digitalocean_spaces_buckets.result", "buckets.0.name", bucketName1),
resource.TestCheckResourceAttr("data.digitalocean_spaces_buckets.result", "buckets.0.region", bucketRegion1),
resource.TestCheckResourceAttr("data.digitalocean_spaces_buckets.result", "buckets.0.bucket_domain_name", bucketDomainName(bucketName1, bucketRegion1)),
resource.TestCheckResourceAttr("data.digitalocean_spaces_buckets.result", "buckets.0.endpoint", bucketEndpoint(bucketRegion1)),
resource.TestCheckResourceAttr("data.digitalocean_spaces_buckets.result", "buckets.0.urn", fmt.Sprintf("do:space:%s", bucketName1)),
),
},
{
// Remove the datasource from the config so Terraform trying to refresh it does not race with
// deleting the bucket resources. By removing the datasource from the config here, this ensures
// that the buckets are deleted after the datasource has been removed from the state.
Config: bucketsConfig,
},
},
})
}