Skip to content

Commit

Permalink
Merge pull request #679 from terraform-providers/sweepers
Browse files Browse the repository at this point in the history
Acceptance Test Sweepers
  • Loading branch information
tombuildsstuff authored Jan 11, 2018
2 parents 8ce631b + 699d1d9 commit eaa3c9e
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
53 changes: 53 additions & 0 deletions azurerm/resource_arm_application_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,65 @@ import (
"os"
"testing"

"log"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func init() {
resource.AddTestSweepers("azurerm_application_gateway", &resource.Sweeper{
Name: "azurerm_application_gateway",
F: testSweepApplicationGateways,
})
}

func testSweepApplicationGateways(region string) error {
armClient, err := buildConfigForSweepers()
if err != nil {
return err
}

client := (*armClient).applicationGatewayClient

log.Printf("Retrieving the Application Gateways..")
results, err := client.ListAll()
if err != nil {
return fmt.Errorf("Error Listing on Application Gateways: %+v", err)
}

for _, network := range *results.Value {
id, err := parseAzureResourceID(*network.ID)
if err != nil {
return fmt.Errorf("Error parsing Azure Resource ID %q", id)
}

resourceGroupName := id.ResourceGroup
name := *network.Name
location := *network.Location

if !shouldSweepAcceptanceTestResource(name, location, region) {
continue
}

log.Printf("Deleting Application Gateway %q", name)
deleteResponse, deleteErr := client.Delete(resourceGroupName, name, make(chan struct{}))
resp := <-deleteResponse
err = <-deleteErr
if err != nil {
if utils.ResponseWasNotFound(resp) {
continue
}

return err
}
}

return nil
}

func TestAccAzureRMApplicationGateway_basic_base(t *testing.T) {
resourceName := "azurerm_application_gateway.test"
ri := acctest.RandInt()
Expand Down
57 changes: 57 additions & 0 deletions azurerm/resource_arm_network_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,69 @@ import (
"fmt"
"testing"

"log"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func init() {
resource.AddTestSweepers("azurerm_network_interface", &resource.Sweeper{
Name: "azurerm_network_interface",
F: testSweepNetworkInterfaces,
Dependencies: []string{
"azurerm_application_gateway",
"azurerm_virtual_machine",
},
})
}

func testSweepNetworkInterfaces(region string) error {
armClient, err := buildConfigForSweepers()
if err != nil {
return err
}

client := (*armClient).ifaceClient

log.Printf("Retrieving the Network Interfaces..")
results, err := client.ListAll()
if err != nil {
return fmt.Errorf("Error Listing on Network Interfaces: %+v", err)
}

for _, network := range *results.Value {
id, err := parseAzureResourceID(*network.ID)
if err != nil {
return fmt.Errorf("Error parsing Azure Resource ID %q", id)
}

resourceGroupName := id.ResourceGroup
name := *network.Name
location := *network.Location

if !shouldSweepAcceptanceTestResource(name, location, region) {
continue
}

log.Printf("Deleting Network Interfaces %q", name)
deleteResponse, deleteErr := client.Delete(resourceGroupName, name, make(chan struct{}))
resp := <-deleteResponse
err = <-deleteErr
if err != nil {
if utils.ResponseWasNotFound(resp) {
continue
}

return err
}
}

return nil
}

func TestAccAzureRMNetworkInterface_basic(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
Expand Down
60 changes: 60 additions & 0 deletions azurerm/resource_arm_virtual_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,71 @@ import (
"net/http"
"testing"

"log"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
utils "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func init() {
resource.AddTestSweepers("azurerm_virtual_network", &resource.Sweeper{
Name: "azurerm_virtual_network",
F: testSweepVirtualNetworks,
Dependencies: []string{
"azurerm_application_gateway",
"azurerm_subnet",
"azurerm_network_interface",
"azurerm_virtual_machine",
},
})
}

func testSweepVirtualNetworks(region string) error {
armClient, err := buildConfigForSweepers()
if err != nil {
return err
}

client := (*armClient).vnetClient

log.Printf("Retrieving the Virtual Networks..")
results, err := client.ListAll()
if err != nil {
return fmt.Errorf("Error Listing on Virtual Networks: %+v", err)
}

for _, network := range *results.Value {
id, err := parseAzureResourceID(*network.ID)
if err != nil {
return fmt.Errorf("Error parsing Azure Resource ID %q", id)
}

resourceGroupName := id.ResourceGroup
name := *network.Name
location := *network.Location

if !shouldSweepAcceptanceTestResource(name, location, region) {
continue
}

log.Printf("Deleting Virtual Network %q", name)
deleteResponse, deleteErr := client.Delete(resourceGroupName, name, make(chan struct{}))
resp := <-deleteResponse
err = <-deleteErr
if err != nil {
if utils.ResponseWasNotFound(resp) {
continue
}

return err
}
}

return nil
}

func TestAccAzureRMVirtualNetwork_basic(t *testing.T) {
resourceName := "azurerm_virtual_network.test"
ri := acctest.RandInt()
Expand Down

0 comments on commit eaa3c9e

Please sign in to comment.