provider/google: Update health check tests (#15102)

* Made resource_compute_health_check_test perform updates.

* Made resource_compute_http_health_check_test perform updates.

* Made resource_compute_https_health_check_test perform updates.
This commit is contained in:
Riley Karson 2017-06-06 05:11:19 -07:00 committed by Paul Stack
parent 6cce74d106
commit 0523ccfad2
4 changed files with 92 additions and 48 deletions

View File

@ -3,19 +3,23 @@ package google
import (
"testing"
"fmt"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccComputeHttpHealthCheck_importBasic(t *testing.T) {
resourceName := "google_compute_http_health_check.foobar"
hhckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHttpHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHttpHealthCheck_basic,
Config: testAccComputeHttpHealthCheck_basic(hhckName),
},
resource.TestStep{

View File

@ -14,13 +14,15 @@ import (
func TestAccComputeHealthCheck_tcp(t *testing.T) {
var healthCheck compute.HealthCheck
hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHealthCheck_tcp,
Config: testAccComputeHealthCheck_tcp(hckName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHealthCheckExists(
"google_compute_health_check.foobar", &healthCheck),
@ -36,13 +38,15 @@ func TestAccComputeHealthCheck_tcp(t *testing.T) {
func TestAccComputeHealthCheck_tcp_update(t *testing.T) {
var healthCheck compute.HealthCheck
hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHealthCheck_tcp,
Config: testAccComputeHealthCheck_tcp(hckName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHealthCheckExists(
"google_compute_health_check.foobar", &healthCheck),
@ -52,7 +56,7 @@ func TestAccComputeHealthCheck_tcp_update(t *testing.T) {
),
},
resource.TestStep{
Config: testAccComputeHealthCheck_tcp_update,
Config: testAccComputeHealthCheck_tcp_update(hckName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHealthCheckExists(
"google_compute_health_check.foobar", &healthCheck),
@ -68,13 +72,15 @@ func TestAccComputeHealthCheck_tcp_update(t *testing.T) {
func TestAccComputeHealthCheck_ssl(t *testing.T) {
var healthCheck compute.HealthCheck
hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHealthCheck_ssl,
Config: testAccComputeHealthCheck_ssl(hckName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHealthCheckExists(
"google_compute_health_check.foobar", &healthCheck),
@ -89,13 +95,15 @@ func TestAccComputeHealthCheck_ssl(t *testing.T) {
func TestAccComputeHealthCheck_http(t *testing.T) {
var healthCheck compute.HealthCheck
hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHealthCheck_http,
Config: testAccComputeHealthCheck_http(hckName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHealthCheckExists(
"google_compute_health_check.foobar", &healthCheck),
@ -110,13 +118,15 @@ func TestAccComputeHealthCheck_http(t *testing.T) {
func TestAccComputeHealthCheck_https(t *testing.T) {
var healthCheck compute.HealthCheck
hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHealthCheck_https,
Config: testAccComputeHealthCheck_https(hckName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHealthCheckExists(
"google_compute_health_check.foobar", &healthCheck),
@ -129,13 +139,15 @@ func TestAccComputeHealthCheck_https(t *testing.T) {
}
func TestAccComputeHealthCheck_tcpAndSsl_shouldFail(t *testing.T) {
hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHealthCheck_tcpAndSsl_shouldFail,
Config: testAccComputeHealthCheck_tcpAndSsl_shouldFail(hckName),
ExpectError: regexp.MustCompile("conflicts with tcp_health_check"),
},
},
@ -222,7 +234,8 @@ func testAccCheckComputeHealthCheckTcpPort(port int64, healthCheck *compute.Heal
}
}
var testAccComputeHealthCheck_tcp = fmt.Sprintf(`
func testAccComputeHealthCheck_tcp(hckName string) string {
return fmt.Sprintf(`
resource "google_compute_health_check" "foobar" {
check_interval_sec = 3
description = "Resource created for Terraform acceptance testing"
@ -233,9 +246,11 @@ resource "google_compute_health_check" "foobar" {
tcp_health_check {
}
}
`, acctest.RandString(10))
`, hckName)
}
var testAccComputeHealthCheck_tcp_update = fmt.Sprintf(`
func testAccComputeHealthCheck_tcp_update(hckName string) string {
return fmt.Sprintf(`
resource "google_compute_health_check" "foobar" {
check_interval_sec = 3
description = "Resource updated for Terraform acceptance testing"
@ -247,9 +262,11 @@ resource "google_compute_health_check" "foobar" {
port = "8080"
}
}
`, acctest.RandString(10))
`, hckName)
}
var testAccComputeHealthCheck_ssl = fmt.Sprintf(`
func testAccComputeHealthCheck_ssl(hckName string) string {
return fmt.Sprintf(`
resource "google_compute_health_check" "foobar" {
check_interval_sec = 3
description = "Resource created for Terraform acceptance testing"
@ -261,9 +278,11 @@ resource "google_compute_health_check" "foobar" {
port = "443"
}
}
`, acctest.RandString(10))
`, hckName)
}
var testAccComputeHealthCheck_http = fmt.Sprintf(`
func testAccComputeHealthCheck_http(hckName string) string {
return fmt.Sprintf(`
resource "google_compute_health_check" "foobar" {
check_interval_sec = 3
description = "Resource created for Terraform acceptance testing"
@ -275,9 +294,11 @@ resource "google_compute_health_check" "foobar" {
port = "80"
}
}
`, acctest.RandString(10))
`, hckName)
}
var testAccComputeHealthCheck_https = fmt.Sprintf(`
func testAccComputeHealthCheck_https(hckName string) string {
return fmt.Sprintf(`
resource "google_compute_health_check" "foobar" {
check_interval_sec = 3
description = "Resource created for Terraform acceptance testing"
@ -289,9 +310,11 @@ resource "google_compute_health_check" "foobar" {
port = "443"
}
}
`, acctest.RandString(10))
`, hckName)
}
var testAccComputeHealthCheck_tcpAndSsl_shouldFail = fmt.Sprintf(`
func testAccComputeHealthCheck_tcpAndSsl_shouldFail(hckName string) string {
return fmt.Sprintf(`
resource "google_compute_health_check" "foobar" {
check_interval_sec = 3
description = "Resource created for Terraform acceptance testing"
@ -305,4 +328,5 @@ resource "google_compute_health_check" "foobar" {
ssl_health_check {
}
}
`, acctest.RandString(10))
`, hckName)
}

View File

@ -13,13 +13,15 @@ import (
func TestAccComputeHttpHealthCheck_basic(t *testing.T) {
var healthCheck compute.HttpHealthCheck
hhckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHttpHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHttpHealthCheck_basic,
Config: testAccComputeHttpHealthCheck_basic(hhckName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHttpHealthCheckExists(
"google_compute_http_health_check.foobar", &healthCheck),
@ -36,13 +38,15 @@ func TestAccComputeHttpHealthCheck_basic(t *testing.T) {
func TestAccComputeHttpHealthCheck_update(t *testing.T) {
var healthCheck compute.HttpHealthCheck
hhckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHttpHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHttpHealthCheck_update1,
Config: testAccComputeHttpHealthCheck_update1(hhckName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHttpHealthCheckExists(
"google_compute_http_health_check.foobar", &healthCheck),
@ -53,7 +57,7 @@ func TestAccComputeHttpHealthCheck_update(t *testing.T) {
),
},
resource.TestStep{
Config: testAccComputeHttpHealthCheck_update2,
Config: testAccComputeHttpHealthCheck_update2(hhckName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHttpHealthCheckExists(
"google_compute_http_health_check.foobar", &healthCheck),
@ -138,35 +142,39 @@ func testAccCheckComputeHttpHealthCheckThresholds(healthy, unhealthy int64, heal
}
}
var testAccComputeHttpHealthCheck_basic = fmt.Sprintf(`
func testAccComputeHttpHealthCheck_basic(hhckName string) string {
return fmt.Sprintf(`
resource "google_compute_http_health_check" "foobar" {
name = "%s"
check_interval_sec = 3
description = "Resource created for Terraform acceptance testing"
healthy_threshold = 3
host = "foobar"
name = "httphealth-test-%s"
port = "80"
request_path = "/health_check"
timeout_sec = 2
unhealthy_threshold = 3
}
`, acctest.RandString(10))
`, hhckName)
}
var testAccComputeHttpHealthCheck_update1 = fmt.Sprintf(`
func testAccComputeHttpHealthCheck_update1(hhckName string) string {
return fmt.Sprintf(`
resource "google_compute_http_health_check" "foobar" {
name = "httphealth-test-%s"
name = "%s"
description = "Resource created for Terraform acceptance testing"
request_path = "/not_default"
}
`, acctest.RandString(10))
`, hhckName)
}
/* Change description, restore request_path to default, and change
* thresholds from defaults */
var testAccComputeHttpHealthCheck_update2 = fmt.Sprintf(`
func testAccComputeHttpHealthCheck_update2(hhckName string) string {
return fmt.Sprintf(`
resource "google_compute_http_health_check" "foobar" {
name = "httphealth-test-%s"
name = "%s"
description = "Resource updated for Terraform acceptance testing"
healthy_threshold = 10
unhealthy_threshold = 10
}
`, acctest.RandString(10))
`, hhckName)
}

View File

@ -13,13 +13,15 @@ import (
func TestAccComputeHttpsHealthCheck_basic(t *testing.T) {
var healthCheck compute.HttpsHealthCheck
hhckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHttpsHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHttpsHealthCheck_basic,
Config: testAccComputeHttpsHealthCheck_basic(hhckName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHttpsHealthCheckExists(
"google_compute_https_health_check.foobar", &healthCheck),
@ -36,13 +38,15 @@ func TestAccComputeHttpsHealthCheck_basic(t *testing.T) {
func TestAccComputeHttpsHealthCheck_update(t *testing.T) {
var healthCheck compute.HttpsHealthCheck
hhckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHttpsHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHttpsHealthCheck_update1,
Config: testAccComputeHttpsHealthCheck_update1(hhckName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHttpsHealthCheckExists(
"google_compute_https_health_check.foobar", &healthCheck),
@ -53,7 +57,7 @@ func TestAccComputeHttpsHealthCheck_update(t *testing.T) {
),
},
resource.TestStep{
Config: testAccComputeHttpsHealthCheck_update2,
Config: testAccComputeHttpsHealthCheck_update2(hhckName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHttpsHealthCheckExists(
"google_compute_https_health_check.foobar", &healthCheck),
@ -138,35 +142,39 @@ func testAccCheckComputeHttpsHealthCheckThresholds(healthy, unhealthy int64, hea
}
}
var testAccComputeHttpsHealthCheck_basic = fmt.Sprintf(`
func testAccComputeHttpsHealthCheck_basic(hhckName string) string {
return fmt.Sprintf(`
resource "google_compute_https_health_check" "foobar" {
check_interval_sec = 3
description = "Resource created for Terraform acceptance testing"
healthy_threshold = 3
host = "foobar"
name = "httpshealth-test-%s"
name = "%s"
port = "80"
request_path = "/health_check"
timeout_sec = 2
unhealthy_threshold = 3
}
`, acctest.RandString(10))
`, hhckName)
}
var testAccComputeHttpsHealthCheck_update1 = fmt.Sprintf(`
func testAccComputeHttpsHealthCheck_update1(hhckName string) string {
return fmt.Sprintf(`
resource "google_compute_https_health_check" "foobar" {
name = "httpshealth-test-%s"
name = "%s"
description = "Resource created for Terraform acceptance testing"
request_path = "/not_default"
}
`, acctest.RandString(10))
`, hhckName)
}
/* Change description, restore request_path to default, and change
* thresholds from defaults */
var testAccComputeHttpsHealthCheck_update2 = fmt.Sprintf(`
func testAccComputeHttpsHealthCheck_update2(hhckName string) string {
return fmt.Sprintf(`
resource "google_compute_https_health_check" "foobar" {
name = "httpshealth-test-%s"
name = "%s"
description = "Resource updated for Terraform acceptance testing"
healthy_threshold = 10
unhealthy_threshold = 10
}
`, acctest.RandString(10))
`, hhckName)
}