From 129c6dce6ae70cd19323b85356703d79900558c2 Mon Sep 17 00:00:00 2001 From: Emily Ye Date: Thu, 6 Sep 2018 23:51:35 -0700 Subject: [PATCH] randomize network name for test --- google/resource_composer_environment_test.go | 35 ++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/google/resource_composer_environment_test.go b/google/resource_composer_environment_test.go index ad3748ee20d..7da79f1ee1e 100644 --- a/google/resource_composer_environment_test.go +++ b/google/resource_composer_environment_test.go @@ -115,6 +115,10 @@ func TestAccComposerEnvironment_withNodeConfig(t *testing.T) { t.Parallel() envName := acctest.RandomWithPrefix("tf-test") + network := acctest.RandomWithPrefix("tf-test") + subnetwork := network + "-1" + serviceAccount := acctest.RandomWithPrefix("tf-test") + var env composer.Environment resource.Test(t, resource.TestCase{ @@ -123,7 +127,7 @@ func TestAccComposerEnvironment_withNodeConfig(t *testing.T) { CheckDestroy: testAccComposerEnvironmentDestroy, Steps: []resource.TestStep{ { - Config: testAccComposerEnvironment_nodeCfg(envName), + Config: testAccComposerEnvironment_nodeCfg(envName, network, subnetwork, serviceAccount), Check: testAccCheckComposerEnvironmentExists("google_composer_environment.test", &env), }, { @@ -133,6 +137,25 @@ func TestAccComposerEnvironment_withNodeConfig(t *testing.T) { }, }, }) + + if env.Config == nil || env.Config.NodeConfig == nil { + t.Fatalf("expected non-nil config and node config") + } + + nodeCfg := env.Config.NodeConfig + + expectedNetwork := fmt.Sprintf("projects/%s/global/networks/%s", getTestProjectFromEnv(), network) + if nodeCfg.Network != expectedNetwork { + t.Errorf("expected Environment network %q, got %q", expectedNetwork, nodeCfg.Network) + } + + expectedSubnetwork := fmt.Sprintf("projects/%s/regions/us-central1/subnetworks/%s", getTestProjectFromEnv(), subnetwork) + if nodeCfg.Subnetwork != expectedSubnetwork { + t.Errorf("expected Environment subnetwork %q, got %q", expectedSubnetwork, nodeCfg.Subnetwork) + } + if !strings.HasPrefix(nodeCfg.ServiceAccount, serviceAccount+"@") { + t.Errorf("expected Environment service account %q to start with name %q", nodeCfg.ServiceAccount, serviceAccount) + } } // Checks behavior of config for creation for attributes that must @@ -283,7 +306,7 @@ resource "google_composer_environment" "test" { `, name) } -func testAccComposerEnvironment_nodeCfg(name string) string { +func testAccComposerEnvironment_nodeCfg(environment, network, subnetwork, serviceAccount string) string { return fmt.Sprintf(` resource "google_composer_environment" "test" { name = "%s" @@ -301,19 +324,19 @@ resource "google_composer_environment" "test" { } resource "google_compute_network" "test" { - name = "composer-test-network" + name = "%s" auto_create_subnetworks = false } resource "google_compute_subnetwork" "test" { - name = "composer-test-subnetwork" + name = "%s" ip_cidr_range = "10.2.0.0/16" region = "us-central1" network = "${google_compute_network.test.self_link}" } resource "google_service_account" "test" { - account_id = "composer-env-account" + account_id = "%s" display_name = "Test Service Account for Composer Environment" } @@ -321,7 +344,7 @@ resource "google_project_iam_member" "composer-worker" { role = "roles/composer.worker" member = "serviceAccount:${google_service_account.test.email}" } -`, name) +`, environment, network, subnetwork, serviceAccount) } func testAccComposerEnvironment_updateOnlyFields(name string) string {