Skip to content

Commit

Permalink
randomize network name for test
Browse files Browse the repository at this point in the history
  • Loading branch information
emilymye committed Sep 7, 2018
1 parent 5b5a837 commit 129c6dc
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions google/resource_composer_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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),
},
{
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -301,27 +324,27 @@ 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"
}
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 {
Expand Down

0 comments on commit 129c6dc

Please sign in to comment.