fix bugs in health check and its tests

This commit is contained in:
Dana Hoffman 2016-11-29 17:39:39 -08:00
parent 20ee56be07
commit 77f0ef4fc1
2 changed files with 7 additions and 96 deletions

View File

@ -59,10 +59,7 @@ func resourceComputeHealthCheck() *schema.Resource {
"port": &schema.Schema{ "port": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
}, Default: 80,
"port_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
}, },
"proxy_header": &schema.Schema{ "proxy_header": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
@ -90,10 +87,7 @@ func resourceComputeHealthCheck() *schema.Resource {
"port": &schema.Schema{ "port": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
}, Default: 443,
"port_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
}, },
"proxy_header": &schema.Schema{ "proxy_header": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
@ -121,15 +115,12 @@ func resourceComputeHealthCheck() *schema.Resource {
"host": &schema.Schema{ "host": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Default: 80,
}, },
"port": &schema.Schema{ "port": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
}, },
"port_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"proxy_header": &schema.Schema{ "proxy_header": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
@ -153,15 +144,12 @@ func resourceComputeHealthCheck() *schema.Resource {
"host": &schema.Schema{ "host": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Default: 443,
}, },
"port": &schema.Schema{ "port": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
}, },
"port_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"proxy_header": &schema.Schema{ "proxy_header": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
@ -243,9 +231,6 @@ func resourceComputeHealthCheckCreate(d *schema.ResourceData, meta interface{})
if val, ok := tcpcheck["port"]; ok { if val, ok := tcpcheck["port"]; ok {
tcpHealthCheck.Port = int64(val.(int)) tcpHealthCheck.Port = int64(val.(int))
} }
if val, ok := tcpcheck["port_name"]; ok {
tcpHealthCheck.PortName = val.(string)
}
if val, ok := tcpcheck["proxy_header"]; ok { if val, ok := tcpcheck["proxy_header"]; ok {
tcpHealthCheck.ProxyHeader = val.(string) tcpHealthCheck.ProxyHeader = val.(string)
} }
@ -267,9 +252,6 @@ func resourceComputeHealthCheckCreate(d *schema.ResourceData, meta interface{})
if val, ok := sslcheck["port"]; ok { if val, ok := sslcheck["port"]; ok {
sslHealthCheck.Port = int64(val.(int)) sslHealthCheck.Port = int64(val.(int))
} }
if val, ok := sslcheck["port_name"]; ok {
sslHealthCheck.PortName = val.(string)
}
if val, ok := sslcheck["proxy_header"]; ok { if val, ok := sslcheck["proxy_header"]; ok {
sslHealthCheck.ProxyHeader = val.(string) sslHealthCheck.ProxyHeader = val.(string)
} }
@ -294,9 +276,6 @@ func resourceComputeHealthCheckCreate(d *schema.ResourceData, meta interface{})
if val, ok := httpcheck["port"]; ok { if val, ok := httpcheck["port"]; ok {
httpHealthCheck.Port = int64(val.(int)) httpHealthCheck.Port = int64(val.(int))
} }
if val, ok := httpcheck["port_name"]; ok {
httpHealthCheck.PortName = val.(string)
}
if val, ok := httpcheck["proxy_header"]; ok { if val, ok := httpcheck["proxy_header"]; ok {
httpHealthCheck.ProxyHeader = val.(string) httpHealthCheck.ProxyHeader = val.(string)
} }
@ -318,9 +297,6 @@ func resourceComputeHealthCheckCreate(d *schema.ResourceData, meta interface{})
if val, ok := httpscheck["port"]; ok { if val, ok := httpscheck["port"]; ok {
httpsHealthCheck.Port = int64(val.(int)) httpsHealthCheck.Port = int64(val.(int))
} }
if val, ok := httpscheck["port_name"]; ok {
httpsHealthCheck.PortName = val.(string)
}
if val, ok := httpscheck["proxy_header"]; ok { if val, ok := httpscheck["proxy_header"]; ok {
httpsHealthCheck.ProxyHeader = val.(string) httpsHealthCheck.ProxyHeader = val.(string)
} }
@ -388,9 +364,6 @@ func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{})
if val, ok := tcpcheck["port"]; ok { if val, ok := tcpcheck["port"]; ok {
tcpHealthCheck.Port = int64(val.(int)) tcpHealthCheck.Port = int64(val.(int))
} }
if val, ok := tcpcheck["port_name"]; ok {
tcpHealthCheck.PortName = val.(string)
}
if val, ok := tcpcheck["proxy_header"]; ok { if val, ok := tcpcheck["proxy_header"]; ok {
tcpHealthCheck.ProxyHeader = val.(string) tcpHealthCheck.ProxyHeader = val.(string)
} }
@ -411,9 +384,6 @@ func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{})
if val, ok := sslcheck["port"]; ok { if val, ok := sslcheck["port"]; ok {
sslHealthCheck.Port = int64(val.(int)) sslHealthCheck.Port = int64(val.(int))
} }
if val, ok := sslcheck["port_name"]; ok {
sslHealthCheck.PortName = val.(string)
}
if val, ok := sslcheck["proxy_header"]; ok { if val, ok := sslcheck["proxy_header"]; ok {
sslHealthCheck.ProxyHeader = val.(string) sslHealthCheck.ProxyHeader = val.(string)
} }
@ -437,9 +407,6 @@ func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{})
if val, ok := httpcheck["port"]; ok { if val, ok := httpcheck["port"]; ok {
httpHealthCheck.Port = int64(val.(int)) httpHealthCheck.Port = int64(val.(int))
} }
if val, ok := httpcheck["port_name"]; ok {
httpHealthCheck.PortName = val.(string)
}
if val, ok := httpcheck["proxy_header"]; ok { if val, ok := httpcheck["proxy_header"]; ok {
httpHealthCheck.ProxyHeader = val.(string) httpHealthCheck.ProxyHeader = val.(string)
} }
@ -461,9 +428,6 @@ func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{})
if val, ok := httpscheck["port"]; ok { if val, ok := httpscheck["port"]; ok {
httpsHealthCheck.Port = int64(val.(int)) httpsHealthCheck.Port = int64(val.(int))
} }
if val, ok := httpscheck["port_name"]; ok {
httpsHealthCheck.PortName = val.(string)
}
if val, ok := httpscheck["proxy_header"]; ok { if val, ok := httpscheck["proxy_header"]; ok {
httpsHealthCheck.ProxyHeader = val.(string) httpsHealthCheck.ProxyHeader = val.(string)
} }
@ -519,9 +483,9 @@ func resourceComputeHealthCheckRead(d *schema.ResourceData, meta interface{}) er
d.Set("unhealthy_threshold", hchk.UnhealthyThreshold) d.Set("unhealthy_threshold", hchk.UnhealthyThreshold)
d.Set("type", hchk.Type) d.Set("type", hchk.Type)
d.Set("tcp_health_check", hchk.TcpHealthCheck) d.Set("tcp_health_check", hchk.TcpHealthCheck)
d.Set("ssl_health_check", hchk.TcpHealthCheck) d.Set("ssl_health_check", hchk.SslHealthCheck)
d.Set("http_health_check", hchk.TcpHealthCheck) d.Set("http_health_check", hchk.HttpHealthCheck)
d.Set("https_health_check", hchk.TcpHealthCheck) d.Set("https_health_check", hchk.HttpsHealthCheck)
d.Set("self_link", hchk.SelfLink) d.Set("self_link", hchk.SelfLink)
d.Set("name", hchk.Name) d.Set("name", hchk.Name)
d.Set("description", hchk.Description) d.Set("description", hchk.Description)

View File

@ -32,30 +32,6 @@ func TestAccComputeHealthCheck_tcp(t *testing.T) {
}) })
} }
func TestAccComputeHealthCheck_tcp_withPortName(t *testing.T) {
var healthCheck compute.HealthCheck
portName := "dummy-port"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHealthCheck_tcp_withPortName(portName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHealthCheckExists(
"google_compute_health_check.foobar", &healthCheck),
testAccCheckComputeHealthCheckTcpPortName(portName, &healthCheck),
// 80 is the default port, so even though we did not set one,
// it should still have a value of 80.
testAccCheckComputeHealthCheckTcpPort(80, &healthCheck),
),
},
},
})
}
func TestAccComputeHealthCheck_ssl(t *testing.T) { func TestAccComputeHealthCheck_ssl(t *testing.T) {
var healthCheck compute.HealthCheck var healthCheck compute.HealthCheck
@ -191,19 +167,6 @@ func testAccCheckComputeHealthCheckTcpPort(port int64, healthCheck *compute.Heal
} }
} }
func testAccCheckComputeHealthCheckTcpPortName(portName string, healthCheck *compute.HealthCheck) resource.TestCheckFunc {
return func(s *terraform.State) error {
if healthCheck.TcpHealthCheck.PortName != portName {
return fmt.Errorf("PortName doesn't match: expected %s, got %s", portName, healthCheck.TcpHealthCheck.PortName)
}
if healthCheck.TcpHealthCheck.Port != 0 {
return fmt.Errorf("Port doesn't match: expected nil, got %v", healthCheck.TcpHealthCheck.Port)
}
return nil
}
}
var testAccComputeHealthCheck_tcp = fmt.Sprintf(` var testAccComputeHealthCheck_tcp = fmt.Sprintf(`
resource "google_compute_health_check" "foobar" { resource "google_compute_health_check" "foobar" {
check_interval_sec = 3 check_interval_sec = 3
@ -217,22 +180,6 @@ resource "google_compute_health_check" "foobar" {
} }
`, acctest.RandString(10)) `, acctest.RandString(10))
func testAccComputeHealthCheck_tcp_withPortName(portName string) string {
return fmt.Sprintf(`
resource "google_compute_health_check" "foobar" {
check_interval_sec = 3
description = "Resource created for Terraform acceptance testing"
healthy_threshold = 3
name = "health-test-%s"
timeout_sec = 2
unhealthy_threshold = 3
tcp_health_check {
port_name = "%s"
}
}
`, acctest.RandString(10), portName)
}
var testAccComputeHealthCheck_ssl = fmt.Sprintf(` var testAccComputeHealthCheck_ssl = fmt.Sprintf(`
resource "google_compute_health_check" "foobar" { resource "google_compute_health_check" "foobar" {
check_interval_sec = 3 check_interval_sec = 3