github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/opc/resource_ip_address_prefix_set_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 TestAccOPCIPAddressPrefixSet_Basic(t *testing.T) { 14 rInt := acctest.RandInt() 15 resourceName := "opc_compute_ip_address_prefix_set.test" 16 resource.Test(t, resource.TestCase{ 17 PreCheck: func() { testAccPreCheck(t) }, 18 Providers: testAccProviders, 19 CheckDestroy: testAccCheckIPAddressPrefixSetDestroy, 20 Steps: []resource.TestStep{ 21 { 22 Config: testAccIPAddressPrefixSetBasic(rInt), 23 Check: resource.ComposeTestCheckFunc( 24 testAccCheckIPAddressPrefixSetExists, 25 resource.TestCheckResourceAttr( 26 resourceName, "tags.#", "2"), 27 resource.TestCheckResourceAttr( 28 resourceName, "prefixes.#", "2"), 29 ), 30 }, 31 { 32 Config: testAccIPAddressPrefixSetBasic_Update(rInt), 33 Check: resource.ComposeTestCheckFunc( 34 resource.TestCheckResourceAttr( 35 resourceName, "tags.#", "1"), 36 resource.TestCheckResourceAttr( 37 resourceName, "prefixes.0", "171.120.0.0/24"), 38 ), 39 }, 40 }, 41 }) 42 } 43 44 func testAccCheckIPAddressPrefixSetExists(s *terraform.State) error { 45 client := testAccProvider.Meta().(*compute.Client).IPAddressPrefixSets() 46 47 for _, rs := range s.RootModule().Resources { 48 if rs.Type != "opc_compute_ip_address_prefix_set" { 49 continue 50 } 51 52 input := compute.GetIPAddressPrefixSetInput{ 53 Name: rs.Primary.Attributes["name"], 54 } 55 if _, err := client.GetIPAddressPrefixSet(&input); err != nil { 56 return fmt.Errorf("Error retrieving state of IP Address Prefix Set %s: %s", input.Name, err) 57 } 58 } 59 60 return nil 61 } 62 63 func testAccCheckIPAddressPrefixSetDestroy(s *terraform.State) error { 64 client := testAccProvider.Meta().(*compute.Client).IPAddressPrefixSets() 65 66 for _, rs := range s.RootModule().Resources { 67 if rs.Type != "opc_compute_ip_address_prefix_set" { 68 continue 69 } 70 71 input := compute.GetIPAddressPrefixSetInput{ 72 Name: rs.Primary.Attributes["name"], 73 } 74 if info, err := client.GetIPAddressPrefixSet(&input); err == nil { 75 return fmt.Errorf("IP Address Prefix Set %s still exists: %#v", input.Name, info) 76 } 77 } 78 79 return nil 80 } 81 82 func testAccIPAddressPrefixSetBasic(rInt int) string { 83 return fmt.Sprintf(` 84 resource "opc_compute_ip_address_prefix_set" "test" { 85 name = "testing-acc-%d" 86 prefixes = ["172.120.0.0/24", "192.168.0.0/16"] 87 description = "acctesting ip address prefix test %d" 88 tags = ["tag1", "tag2"] 89 }`, rInt, rInt) 90 } 91 92 func testAccIPAddressPrefixSetBasic_Update(rInt int) string { 93 return fmt.Sprintf(` 94 resource "opc_compute_ip_address_prefix_set" "test" { 95 name = "testing-acc-%d" 96 description = "acctesting ip address prefix test updated %d" 97 prefixes = ["171.120.0.0/24", "192.168.0.0/16"] 98 tags = ["tag1"] 99 }`, rInt, rInt) 100 }