github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/google/resource_compute_route_test.go (about) 1 package google 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 "google.golang.org/api/compute/v1" 10 ) 11 12 func TestAccComputeRoute_basic(t *testing.T) { 13 var route compute.Route 14 15 resource.Test(t, resource.TestCase{ 16 PreCheck: func() { testAccPreCheck(t) }, 17 Providers: testAccProviders, 18 CheckDestroy: testAccCheckComputeRouteDestroy, 19 Steps: []resource.TestStep{ 20 resource.TestStep{ 21 Config: testAccComputeRoute_basic, 22 Check: resource.ComposeTestCheckFunc( 23 testAccCheckComputeRouteExists( 24 "google_compute_route.foobar", &route), 25 ), 26 }, 27 }, 28 }) 29 } 30 31 func testAccCheckComputeRouteDestroy(s *terraform.State) error { 32 config := testAccProvider.Meta().(*Config) 33 34 for _, rs := range s.RootModule().Resources { 35 if rs.Type != "google_compute_route" { 36 continue 37 } 38 39 _, err := config.clientCompute.Routes.Get( 40 config.Project, rs.Primary.ID).Do() 41 if err == nil { 42 return fmt.Errorf("Route still exists") 43 } 44 } 45 46 return nil 47 } 48 49 func testAccCheckComputeRouteExists(n string, route *compute.Route) resource.TestCheckFunc { 50 return func(s *terraform.State) error { 51 rs, ok := s.RootModule().Resources[n] 52 if !ok { 53 return fmt.Errorf("Not found: %s", n) 54 } 55 56 if rs.Primary.ID == "" { 57 return fmt.Errorf("No ID is set") 58 } 59 60 config := testAccProvider.Meta().(*Config) 61 62 found, err := config.clientCompute.Routes.Get( 63 config.Project, rs.Primary.ID).Do() 64 if err != nil { 65 return err 66 } 67 68 if found.Name != rs.Primary.ID { 69 return fmt.Errorf("Route not found") 70 } 71 72 *route = *found 73 74 return nil 75 } 76 } 77 78 const testAccComputeRoute_basic = ` 79 resource "google_compute_network" "foobar" { 80 name = "terraform-test" 81 ipv4_range = "10.0.0.0/16" 82 } 83 84 resource "google_compute_route" "foobar" { 85 name = "terraform-test" 86 dest_range = "15.0.0.0/24" 87 network = "${google_compute_network.foobar.name}" 88 next_hop_ip = "10.0.1.5" 89 priority = 100 90 }`