Skip to content

Commit

Permalink
provider/google: Update health check tests (#15102)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
rileykarson authored and stack72 committed Jun 6, 2017
1 parent 6cce74d commit 0523ccf
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
62 changes: 43 additions & 19 deletions builtin/providers/google/resource_compute_health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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"),
},
},
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -305,4 +328,5 @@ resource "google_compute_health_check" "foobar" {
ssl_health_check {
}
}
`, acctest.RandString(10))
`, hckName)
}
36 changes: 22 additions & 14 deletions builtin/providers/google/resource_compute_http_health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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)
}
Loading

0 comments on commit 0523ccf

Please sign in to comment.