@ -6,9 +6,12 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"google.golang.org/api/compute/v1"
)
func TestAccComputeHttpHealthCheck_basic ( t * testing . T ) {
var healthCheck compute . HttpHealthCheck
resource . Test ( t , resource . TestCase {
PreCheck : func ( ) { testAccPreCheck ( t ) } ,
Providers : testAccProviders ,
@ -18,7 +21,11 @@ func TestAccComputeHttpHealthCheck_basic(t *testing.T) {
Config : testAccComputeHttpHealthCheck_basic ,
Check : resource . ComposeTestCheckFunc (
testAccCheckComputeHttpHealthCheckExists (
"google_compute_http_health_check.foobar" ) ,
"google_compute_http_health_check.foobar" , & healthCheck ) ,
testAccCheckComputeHttpHealthCheckRequestPath (
"/health_check" , & healthCheck ) ,
testAccCheckComputeHttpHealthCheckThresholds (
3 , 3 , & healthCheck ) ,
) ,
} ,
} ,
@ -38,6 +45,10 @@ func TestAccComputeHttpHealthCheck_update(t *testing.T) {
Check : resource . ComposeTestCheckFunc (
testAccCheckComputeHttpHealthCheckExists (
"google_compute_http_health_check.foobar" , & healthCheck ) ,
testAccCheckComputeHttpHealthCheckRequestPath (
"/not_default" , & healthCheck ) ,
testAccCheckComputeHttpHealthCheckThresholds (
2 , 2 , & healthCheck ) ,
) ,
} ,
resource . TestStep {
@ -45,6 +56,10 @@ func TestAccComputeHttpHealthCheck_update(t *testing.T) {
Check : resource . ComposeTestCheckFunc (
testAccCheckComputeHttpHealthCheckExists (
"google_compute_http_health_check.foobar" , & healthCheck ) ,
testAccCheckComputeHttpHealthCheckRequestPath (
"/" , & healthCheck ) ,
testAccCheckComputeHttpHealthCheckThresholds (
10 , 10 , & healthCheck ) ,
) ,
} ,
} ,
@ -69,7 +84,7 @@ func testAccCheckComputeHttpHealthCheckDestroy(s *terraform.State) error {
return nil
}
func testAccCheckComputeHttpHealthCheckExists ( n string ) resource . TestCheckFunc {
func testAccCheckComputeHttpHealthCheckExists ( n string , healthCheck * compute . HttpHealthCheck ) resource . TestCheckFunc {
return func ( s * terraform . State ) error {
rs , ok := s . RootModule ( ) . Resources [ n ]
if ! ok {
@ -92,6 +107,32 @@ func testAccCheckComputeHttpHealthCheckExists(n string) resource.TestCheckFunc {
return fmt . Errorf ( "HttpHealthCheck not found" )
}
* healthCheck = * found
return nil
}
}
func testAccCheckComputeHttpHealthCheckRequestPath ( path string , healthCheck * compute . HttpHealthCheck ) resource . TestCheckFunc {
return func ( s * terraform . State ) error {
if healthCheck . RequestPath != path {
return fmt . Errorf ( "RequestPath doesn't match: expected %d, got %d" , path , healthCheck . RequestPath )
}
return nil
}
}
func testAccCheckComputeHttpHealthCheckThresholds ( healthy , unhealthy int64 , healthCheck * compute . HttpHealthCheck ) resource . TestCheckFunc {
return func ( s * terraform . State ) error {
if healthCheck . HealthyThreshold != healthy {
return fmt . Errorf ( "HealthyThreshold doesn't match: expected %d, got %d" , healthy , healthCheck . HealthyThreshold )
}
if healthCheck . UnhealthyThreshold != unhealthy {
return fmt . Errorf ( "UnhealthyThreshold doesn't match: expected %d, got %d" , unhealthy , healthCheck . UnhealthyThreshold )
}
return nil
}
}