forked from digitalocean/terraform-provider-digitalocean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasource_digitalocean_container_registry_test.go
85 lines (70 loc) · 2.23 KB
/
datasource_digitalocean_container_registry_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package digitalocean
import (
"context"
"fmt"
"testing"
"github.com/digitalocean/godo"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func TestAccDataSourceDigitalOceanContainerRegistry_Basic(t *testing.T) {
var reg godo.Registry
regName := randomTestName()
resourceConfig := fmt.Sprintf(`
resource "digitalocean_container_registry" "foo" {
name = "%s"
subscription_tier_slug = "basic"
}
`, regName)
dataSourceConfig := `
data "digitalocean_container_registry" "foobar" {
name = digitalocean_container_registry.foo.name
}
`
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: resourceConfig,
},
{
Config: resourceConfig + dataSourceConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckDataSourceDigitalOceanContainerRegistryExists("data.digitalocean_container_registry.foobar", ®),
resource.TestCheckResourceAttr(
"data.digitalocean_container_registry.foobar", "name", regName),
resource.TestCheckResourceAttr(
"data.digitalocean_container_registry.foobar", "subscription_tier_slug", "basic"),
resource.TestCheckResourceAttrSet(
"data.digitalocean_container_registry.foobar", "region"),
resource.TestCheckResourceAttrSet(
"data.digitalocean_container_registry.foobar", "created_at"),
resource.TestCheckResourceAttrSet(
"data.digitalocean_container_registry.foobar", "storage_usage_bytes"),
),
},
},
})
}
func testAccCheckDataSourceDigitalOceanContainerRegistryExists(n string, reg *godo.Registry) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No registry ID is set")
}
client := testAccProvider.Meta().(*CombinedConfig).godoClient()
foundReg, _, err := client.Registry.Get(context.Background())
if err != nil {
return err
}
if foundReg.Name != rs.Primary.ID {
return fmt.Errorf("Registry not found")
}
*reg = *foundReg
return nil
}
}