github.com/ndarilek/terraform@v0.3.8-0.20150320140257-d3135c1b2bac/builtin/providers/google/resource_compute_http_health_check_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 ) 10 11 func TestAccComputeHttpHealthCheck_basic(t *testing.T) { 12 resource.Test(t, resource.TestCase{ 13 PreCheck: func() { testAccPreCheck(t) }, 14 Providers: testAccProviders, 15 CheckDestroy: testAccCheckComputeHttpHealthCheckDestroy, 16 Steps: []resource.TestStep{ 17 resource.TestStep{ 18 Config: testAccComputeHttpHealthCheck_basic, 19 Check: resource.ComposeTestCheckFunc( 20 testAccCheckComputeHttpHealthCheckExists( 21 "google_compute_http_health_check.foobar"), 22 ), 23 }, 24 }, 25 }) 26 } 27 28 func testAccCheckComputeHttpHealthCheckDestroy(s *terraform.State) error { 29 config := testAccProvider.Meta().(*Config) 30 31 for _, rs := range s.RootModule().Resources { 32 if rs.Type != "google_compute_http_health_check" { 33 continue 34 } 35 36 _, err := config.clientCompute.HttpHealthChecks.Get( 37 config.Project, rs.Primary.ID).Do() 38 if err == nil { 39 return fmt.Errorf("HttpHealthCheck still exists") 40 } 41 } 42 43 return nil 44 } 45 46 func testAccCheckComputeHttpHealthCheckExists(n string) resource.TestCheckFunc { 47 return func(s *terraform.State) error { 48 rs, ok := s.RootModule().Resources[n] 49 if !ok { 50 return fmt.Errorf("Not found: %s", n) 51 } 52 53 if rs.Primary.ID == "" { 54 return fmt.Errorf("No ID is set") 55 } 56 57 config := testAccProvider.Meta().(*Config) 58 59 found, err := config.clientCompute.HttpHealthChecks.Get( 60 config.Project, rs.Primary.ID).Do() 61 if err != nil { 62 return err 63 } 64 65 if found.Name != rs.Primary.ID { 66 return fmt.Errorf("HttpHealthCheck not found") 67 } 68 69 return nil 70 } 71 } 72 73 const testAccComputeHttpHealthCheck_basic = ` 74 resource "google_compute_http_health_check" "foobar" { 75 check_interval_sec = 3 76 description = "Resource created for Terraform acceptance testing" 77 healthy_threshold = 3 78 host = "foobar" 79 name = "terraform-test" 80 port = "80" 81 request_path = "/health_check" 82 timeout_sec = 2 83 unhealthy_threshold = 3 84 } 85 `