Skip to content

Commit

Permalink
Update node pool tests to use bootstrapped network (#9348)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuyama1 authored Oct 26, 2023
1 parent f3db9dd commit 585b10b
Show file tree
Hide file tree
Showing 2 changed files with 465 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import (
func TestAccContainerClusterDatasource_zonal(t *testing.T) {
t.Parallel()

networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccContainerClusterDatasource_zonal(acctest.RandString(t, 10)),
Config: testAccContainerClusterDatasource_zonal(acctest.RandString(t, 10), networkName, subnetworkName),
Check: resource.ComposeTestCheckFunc(
acctest.CheckDataSourceStateMatchesResourceStateWithIgnores(
"data.google_container_cluster.kubes",
Expand All @@ -38,12 +41,15 @@ func TestAccContainerClusterDatasource_zonal(t *testing.T) {
func TestAccContainerClusterDatasource_regional(t *testing.T) {
t.Parallel()

networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccContainerClusterDatasource_regional(acctest.RandString(t, 10)),
Config: testAccContainerClusterDatasource_regional(acctest.RandString(t, 10), networkName, subnetworkName),
Check: resource.ComposeTestCheckFunc(
acctest.CheckDataSourceStateMatchesResourceStateWithIgnores(
"data.google_container_cluster.kubes",
Expand All @@ -62,34 +68,40 @@ func TestAccContainerClusterDatasource_regional(t *testing.T) {
})
}

func testAccContainerClusterDatasource_zonal(suffix string) string {
func testAccContainerClusterDatasource_zonal(suffix, networkName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "kubes" {
name = "tf-test-cluster-%s"
location = "us-central1-a"
initial_node_count = 1
deletion_protection = false
network = "%s"
subnetwork = "%s"
}
data "google_container_cluster" "kubes" {
name = google_container_cluster.kubes.name
location = google_container_cluster.kubes.location
}
`, suffix)
`, suffix, networkName, subnetworkName)
}

func testAccContainerClusterDatasource_regional(suffix string) string {
func testAccContainerClusterDatasource_regional(suffix, networkName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "kubes" {
name = "tf-test-cluster-%s"
location = "us-central1"
initial_node_count = 1
deletion_protection = false
network = "%s"
subnetwork = "%s"
}
data "google_container_cluster" "kubes" {
name = google_container_cluster.kubes.name
location = google_container_cluster.kubes.location
}
`, suffix)
`, suffix, networkName, subnetworkName)
}
Loading

0 comments on commit 585b10b

Please sign in to comment.