Skip to content

Commit

Permalink
Autogenerate {{Resource}}Destroy in tests. (#2317)
Browse files Browse the repository at this point in the history
  • Loading branch information
modular-magician authored and nat-henderson committed Dec 5, 2018
1 parent db811e1 commit 62f53ea
Show file tree
Hide file tree
Showing 47 changed files with 573 additions and 464 deletions.
23 changes: 23 additions & 0 deletions google/resource_compute_address_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccComputeAddress_addressBasicExample(t *testing.T) {
Expand Down Expand Up @@ -147,3 +148,25 @@ resource "google_compute_instance" "instance_with_ip" {
`, val, val,
)
}

func testAccCheckComputeAddressDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_address" {
continue
}

config := testAccProvider.Meta().(*Config)

url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/addresses/{{name}}")
if err != nil {
return err
}

_, err = sendRequest(config, "GET", url, nil)
if err == nil {
return fmt.Errorf("ComputeAddress still exists at %s", url)
}
}

return nil
}
21 changes: 0 additions & 21 deletions google/resource_compute_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccComputeAddress_basic(t *testing.T) {
Expand Down Expand Up @@ -79,26 +78,6 @@ func TestAccComputeAddress_internal(t *testing.T) {
})
}

func testAccCheckComputeAddressDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_address" {
continue
}

addressId, err := parseComputeAddressId(rs.Primary.ID, config)

_, err = config.clientCompute.Addresses.Get(
config.Project, addressId.Region, addressId.Name).Do()
if err == nil {
return fmt.Errorf("Address still exists")
}
}

return nil
}

func testAccComputeAddress_basic(i string) string {
return fmt.Sprintf(`
resource "google_compute_address" "foobar" {
Expand Down
23 changes: 23 additions & 0 deletions google/resource_compute_autoscaler_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccComputeAutoscaler_autoscalerBasicExample(t *testing.T) {
Expand Down Expand Up @@ -104,3 +105,25 @@ data "google_compute_image" "debian_9" {
`, val, val, val, val,
)
}

func testAccCheckComputeAutoscalerDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_autoscaler" {
continue
}

config := testAccProvider.Meta().(*Config)

url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/autoscalers/{{name}}")
if err != nil {
return err
}

_, err = sendRequest(config, "GET", url, nil)
if err == nil {
return fmt.Errorf("ComputeAutoscaler still exists at %s", url)
}
}

return nil
}
20 changes: 0 additions & 20 deletions google/resource_compute_autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,6 @@ func TestAccComputeAutoscaler_multicondition(t *testing.T) {
})
}

func testAccCheckComputeAutoscalerDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_autoscaler" {
continue
}

idParts := strings.Split(rs.Primary.ID, "/")
zone, name := idParts[0], idParts[1]
_, err := config.clientCompute.Autoscalers.Get(
config.Project, zone, name).Do()
if err == nil {
return fmt.Errorf("Autoscaler still exists")
}
}

return nil
}

func testAccCheckComputeAutoscalerExists(n string, ascaler *compute.Autoscaler) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down
23 changes: 23 additions & 0 deletions google/resource_compute_backend_bucket_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccComputeBackendBucket_backendBucketBasicExample(t *testing.T) {
Expand Down Expand Up @@ -58,3 +59,25 @@ resource "google_storage_bucket" "image_bucket" {
`, val, val,
)
}

func testAccCheckComputeBackendBucketDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_backend_bucket" {
continue
}

config := testAccProvider.Meta().(*Config)

url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/backendBuckets/{{name}}")
if err != nil {
return err
}

_, err = sendRequest(config, "GET", url, nil)
if err == nil {
return fmt.Errorf("ComputeBackendBucket still exists at %s", url)
}
}

return nil
}
18 changes: 0 additions & 18 deletions google/resource_compute_backend_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,6 @@ func TestAccComputeBackendBucket_basicModified(t *testing.T) {
}
}

func testAccCheckComputeBackendBucketDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_backend_bucket" {
continue
}

_, err := config.clientCompute.BackendBuckets.Get(
config.Project, rs.Primary.ID).Do()
if err == nil {
return fmt.Errorf("Backend bucket %s still exists", rs.Primary.ID)
}
}

return nil
}

func testAccCheckComputeBackendBucketExists(n string, svc *compute.BackendBucket) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down
23 changes: 23 additions & 0 deletions google/resource_compute_firewall_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccComputeFirewall_firewallBasicExample(t *testing.T) {
Expand Down Expand Up @@ -66,3 +67,25 @@ resource "google_compute_network" "default" {
`, val, val,
)
}

func testAccCheckComputeFirewallDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_firewall" {
continue
}

config := testAccProvider.Meta().(*Config)

url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/firewalls/{{name}}")
if err != nil {
return err
}

_, err = sendRequest(config, "GET", url, nil)
if err == nil {
return fmt.Errorf("ComputeFirewall still exists at %s", url)
}
}

return nil
}
18 changes: 0 additions & 18 deletions google/resource_compute_firewall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,24 +283,6 @@ func TestAccComputeFirewall_disabled(t *testing.T) {
})
}

func testAccCheckComputeFirewallDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_firewall" {
continue
}

_, err := config.clientCompute.Firewalls.Get(
config.Project, rs.Primary.ID).Do()
if err == nil {
return fmt.Errorf("Firewall still exists")
}
}

return nil
}

func testAccCheckComputeFirewallExists(n string, firewall *compute.Firewall) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down
23 changes: 23 additions & 0 deletions google/resource_compute_forwarding_rule_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccComputeForwardingRule_forwardingRuleBasicExample(t *testing.T) {
Expand Down Expand Up @@ -56,3 +57,25 @@ resource "google_compute_target_pool" "default" {
`, val, val,
)
}

func testAccCheckComputeForwardingRuleDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_forwarding_rule" {
continue
}

config := testAccProvider.Meta().(*Config)

url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/forwardingRules/{{name}}")
if err != nil {
return err
}

_, err = sendRequest(config, "GET", url, nil)
if err == nil {
return fmt.Errorf("ComputeForwardingRule still exists at %s", url)
}
}

return nil
}
19 changes: 0 additions & 19 deletions google/resource_compute_forwarding_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccComputeForwardingRule_update(t *testing.T) {
Expand Down Expand Up @@ -142,24 +141,6 @@ func TestAccComputeForwardingRule_networkTier(t *testing.T) {
})
}

func testAccCheckComputeForwardingRuleDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_forwarding_rule" {
continue
}

_, err := config.clientCompute.ForwardingRules.Get(
config.Project, config.Region, rs.Primary.ID).Do()
if err == nil {
return fmt.Errorf("ForwardingRule still exists")
}
}

return nil
}

func testAccComputeForwardingRule_basic(poolName, ruleName string) string {
return fmt.Sprintf(`
resource "google_compute_target_pool" "foo-tp" {
Expand Down
23 changes: 23 additions & 0 deletions google/resource_compute_global_address_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccComputeGlobalAddress_globalAddressBasicExample(t *testing.T) {
Expand Down Expand Up @@ -50,3 +51,25 @@ resource "google_compute_global_address" "default" {
`, val,
)
}

func testAccCheckComputeGlobalAddressDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_global_address" {
continue
}

config := testAccProvider.Meta().(*Config)

url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/addresses/{{name}}")
if err != nil {
return err
}

_, err = sendRequest(config, "GET", url, nil)
if err == nil {
return fmt.Errorf("ComputeGlobalAddress still exists at %s", url)
}
}

return nil
}
18 changes: 0 additions & 18 deletions google/resource_compute_global_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,6 @@ func TestAccComputeGlobalAddress_internal(t *testing.T) {
})
}

func testAccCheckComputeGlobalAddressDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_global_address" {
continue
}

_, err := config.clientCompute.GlobalAddresses.Get(
config.Project, rs.Primary.ID).Do()
if err == nil {
return fmt.Errorf("Address still exists")
}
}

return nil
}

func testAccCheckComputeGlobalAddressExists(n string, addr *compute.Address) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down
Loading

0 comments on commit 62f53ea

Please sign in to comment.