provider/google: fix url map test and update logic (#12317)

This commit is contained in:
Dana Hoffman 2017-03-01 01:47:12 -08:00 committed by Paul Stack
parent bf10e5519d
commit 0bf54f4fe4
2 changed files with 20 additions and 10 deletions

View File

@ -599,8 +599,8 @@ func resourceComputeUrlMapUpdate(d *schema.ResourceData, meta interface{}) error
urlMap.PathMatchers = newPathMatchers urlMap.PathMatchers = newPathMatchers
} }
if d.HasChange("tests") { if d.HasChange("test") {
_oldTests, _newTests := d.GetChange("path_matcher") _oldTests, _newTests := d.GetChange("test")
_oldTestsMap := make(map[string]interface{}) _oldTestsMap := make(map[string]interface{})
_newTestsMap := make(map[string]interface{}) _newTestsMap := make(map[string]interface{})

View File

@ -10,13 +10,16 @@ import (
) )
func TestAccComputeUrlMap_basic(t *testing.T) { func TestAccComputeUrlMap_basic(t *testing.T) {
bsName := fmt.Sprintf("urlmap-test-%s", acctest.RandString(10))
hcName := fmt.Sprintf("urlmap-test-%s", acctest.RandString(10))
umName := fmt.Sprintf("urlmap-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckComputeUrlMapDestroy, CheckDestroy: testAccCheckComputeUrlMapDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeUrlMap_basic1, Config: testAccComputeUrlMap_basic1(bsName, hcName, umName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeUrlMapExists( testAccCheckComputeUrlMapExists(
"google_compute_url_map.foobar"), "google_compute_url_map.foobar"),
@ -27,13 +30,16 @@ func TestAccComputeUrlMap_basic(t *testing.T) {
} }
func TestAccComputeUrlMap_update_path_matcher(t *testing.T) { func TestAccComputeUrlMap_update_path_matcher(t *testing.T) {
bsName := fmt.Sprintf("urlmap-test-%s", acctest.RandString(10))
hcName := fmt.Sprintf("urlmap-test-%s", acctest.RandString(10))
umName := fmt.Sprintf("urlmap-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckComputeUrlMapDestroy, CheckDestroy: testAccCheckComputeUrlMapDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccComputeUrlMap_basic1, Config: testAccComputeUrlMap_basic1(bsName, hcName, umName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeUrlMapExists( testAccCheckComputeUrlMapExists(
"google_compute_url_map.foobar"), "google_compute_url_map.foobar"),
@ -41,7 +47,7 @@ func TestAccComputeUrlMap_update_path_matcher(t *testing.T) {
}, },
resource.TestStep{ resource.TestStep{
Config: testAccComputeUrlMap_basic2, Config: testAccComputeUrlMap_basic2(bsName, hcName, umName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckComputeUrlMapExists( testAccCheckComputeUrlMapExists(
"google_compute_url_map.foobar"), "google_compute_url_map.foobar"),
@ -120,7 +126,8 @@ func testAccCheckComputeUrlMapExists(n string) resource.TestCheckFunc {
} }
} }
var testAccComputeUrlMap_basic1 = fmt.Sprintf(` func testAccComputeUrlMap_basic1(bsName, hcName, umName string) string {
return fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" { resource "google_compute_backend_service" "foobar" {
name = "urlmap-test-%s" name = "urlmap-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"] health_checks = ["${google_compute_http_health_check.zero.self_link}"]
@ -157,9 +164,11 @@ resource "google_compute_url_map" "foobar" {
service = "${google_compute_backend_service.foobar.self_link}" service = "${google_compute_backend_service.foobar.self_link}"
} }
} }
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10)) `, bsName, hcName, umName)
}
var testAccComputeUrlMap_basic2 = fmt.Sprintf(` func testAccComputeUrlMap_basic2(bsName, hcName, umName string) string {
return fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" { resource "google_compute_backend_service" "foobar" {
name = "urlmap-test-%s" name = "urlmap-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"] health_checks = ["${google_compute_http_health_check.zero.self_link}"]
@ -192,11 +201,12 @@ resource "google_compute_url_map" "foobar" {
test { test {
host = "mysite.com" host = "mysite.com"
path = "/*" path = "/test"
service = "${google_compute_backend_service.foobar.self_link}" service = "${google_compute_backend_service.foobar.self_link}"
} }
} }
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10)) `, bsName, hcName, umName)
}
var testAccComputeUrlMap_advanced1 = fmt.Sprintf(` var testAccComputeUrlMap_advanced1 = fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" { resource "google_compute_backend_service" "foobar" {