github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/opc/resource_ip_network_exchange_test.go (about)

     1  package opc
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/go-oracle-terraform/compute"
     8  	"github.com/hashicorp/terraform/helper/acctest"
     9  	"github.com/hashicorp/terraform/helper/resource"
    10  	"github.com/hashicorp/terraform/terraform"
    11  )
    12  
    13  func TestAccOPCIPNetworkExchange_Basic(t *testing.T) {
    14  	ri := acctest.RandInt()
    15  	config := fmt.Sprintf(testAccIPNetworkExchangeBasic, ri)
    16  
    17  	resource.Test(t, resource.TestCase{
    18  		PreCheck:     func() { testAccPreCheck(t) },
    19  		Providers:    testAccProviders,
    20  		CheckDestroy: testAccCheckIPNetworkExchangeDestroy,
    21  		Steps: []resource.TestStep{
    22  			{
    23  				Config: config,
    24  				Check:  testAccCheckIPNetworkExchangeExists,
    25  			},
    26  		},
    27  	})
    28  }
    29  
    30  func testAccCheckIPNetworkExchangeExists(s *terraform.State) error {
    31  	client := testAccProvider.Meta().(*compute.Client).IPNetworkExchanges()
    32  
    33  	for _, rs := range s.RootModule().Resources {
    34  		if rs.Type != "opc_compute_ip_network_exchange" {
    35  			continue
    36  		}
    37  
    38  		input := compute.GetIPNetworkExchangeInput{
    39  			Name: rs.Primary.Attributes["name"],
    40  		}
    41  		if _, err := client.GetIPNetworkExchange(&input); err != nil {
    42  			return fmt.Errorf("Error retrieving state of ip network exchange %s: %s", input.Name, err)
    43  		}
    44  	}
    45  
    46  	return nil
    47  }
    48  
    49  func testAccCheckIPNetworkExchangeDestroy(s *terraform.State) error {
    50  	client := testAccProvider.Meta().(*compute.Client).IPNetworkExchanges()
    51  
    52  	for _, rs := range s.RootModule().Resources {
    53  		if rs.Type != "opc_compute_ip_network_exchange" {
    54  			continue
    55  		}
    56  
    57  		input := compute.GetIPNetworkExchangeInput{
    58  			Name: rs.Primary.Attributes["name"],
    59  		}
    60  		if info, err := client.GetIPNetworkExchange(&input); err == nil {
    61  			return fmt.Errorf("IPNetworkExchange %s still exists: %#v", input.Name, info)
    62  		}
    63  	}
    64  
    65  	return nil
    66  }
    67  
    68  var testAccIPNetworkExchangeBasic = `
    69  resource "opc_compute_ip_network_exchange" "test" {
    70    name = "test_ip_network_exchange-%d"
    71    description = "test ip network exchange"
    72  }
    73  `