From 56f06c21704d3793be2280fad6e7f983d2c4e822 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Thu, 26 Sep 2024 19:21:36 +0000 Subject: [PATCH] container: fix storage pool resource names in test (#11832) [upstream:8817cecb1e2562ca433901e50abfbc530b3f3f9e] Signed-off-by: Modular Magician --- .changelog/11832.txt | 3 +++ google/acctest/bootstrap_test_utils.go | 9 +++++++- .../resource_container_cluster_test.go | 23 ++----------------- .../resource_container_node_pool_test.go | 21 ++++++----------- 4 files changed, 20 insertions(+), 36 deletions(-) create mode 100644 .changelog/11832.txt diff --git a/.changelog/11832.txt b/.changelog/11832.txt new file mode 100644 index 00000000000..42b910df155 --- /dev/null +++ b/.changelog/11832.txt @@ -0,0 +1,3 @@ +```release-note:none + +``` \ No newline at end of file diff --git a/google/acctest/bootstrap_test_utils.go b/google/acctest/bootstrap_test_utils.go index 46fdd9924e4..437088baa9b 100644 --- a/google/acctest/bootstrap_test_utils.go +++ b/google/acctest/bootstrap_test_utils.go @@ -1178,7 +1178,14 @@ func BootstrapComputeStoragePool(t *testing.T, storagePoolName, storagePoolType if err != nil { t.Fatalf("Error getting storage pool %s: %s", storagePoolName, err) } - return storagePool.SelfLink + + storagePoolResourceName, err := tpgresource.GetRelativePath(storagePool.SelfLink) + + if err != nil { + t.Fatal("Failed to extract Storage Pool resource name from URL.") + } + + return storagePoolResourceName } func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *transport_tpg.Config) (string, error) { diff --git a/google/services/container/resource_container_cluster_test.go b/google/services/container/resource_container_cluster_test.go index b2d5ccb70fa..34075be60d3 100644 --- a/google/services/container/resource_container_cluster_test.go +++ b/google/services/container/resource_container_cluster_test.go @@ -10613,11 +10613,7 @@ func TestAccContainerCluster_storagePoolsWithNodePool(t *testing.T) { subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) location := envvar.GetTestZoneFromEnv() - storagePoolNameURL := acctest.BootstrapComputeStoragePool(t, "basic-1", "hyperdisk-balanced") - storagePoolResourceName, err := extractSPName(storagePoolNameURL) - if err != nil { - t.Fatal("Failed to extract Storage Pool resource name from URL.") - } + storagePoolResourceName := acctest.BootstrapComputeStoragePool(t, "basic-1", "hyperdisk-balanced") acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -10670,11 +10666,7 @@ func TestAccContainerCluster_storagePoolsWithNodeConfig(t *testing.T) { subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) location := envvar.GetTestZoneFromEnv() - storagePoolNameURL := acctest.BootstrapComputeStoragePool(t, "basic-1", "hyperdisk-balanced") - storagePoolResourceName, err := extractSPName(storagePoolNameURL) - if err != nil { - t.Fatal("Failed to extract Storage Pool resource name from URL.") - } + storagePoolResourceName := acctest.BootstrapComputeStoragePool(t, "basic-1", "hyperdisk-balanced") acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -10716,17 +10708,6 @@ resource "google_container_cluster" "storage_pools_with_node_config" { `, cluster, location, networkName, subnetworkName, storagePoolResourceName) } -func extractSPName(url string) (string, error) { - re := regexp.MustCompile(`https://www\.googleapis\.com/compute/beta/(projects/[^"]+)`) - matches := re.FindStringSubmatch(url) - - if len(matches) > 1 { - return matches[1], nil - } else { - return "", fmt.Errorf("no match found") - } -} - func TestAccContainerCluster_withAutopilotGcpFilestoreCsiDriver(t *testing.T) { t.Parallel() diff --git a/google/services/container/resource_container_node_pool_test.go b/google/services/container/resource_container_node_pool_test.go index 19d3c2d3138..c6e116540a4 100644 --- a/google/services/container/resource_container_node_pool_test.go +++ b/google/services/container/resource_container_node_pool_test.go @@ -4690,11 +4690,7 @@ func TestAccContainerNodePool_storagePools(t *testing.T) { subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) location := envvar.GetTestZoneFromEnv() - storagePoolNameURL := acctest.BootstrapComputeStoragePool(t, "basic-1", "hyperdisk-balanced") - storagePoolResourceName, err := extractSPName(storagePoolNameURL) - if err != nil { - t.Fatal("Failed to extract Storage Pool resource name from URL.") - } + storagePoolResourceName := acctest.BootstrapComputeStoragePool(t, "basic-1", "hyperdisk-balanced") acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -4753,11 +4749,8 @@ func TestAccContainerNodePool_withMachineDiskStoragePoolsUpdate(t *testing.T) { subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) location := envvar.GetTestZoneFromEnv() - storagePoolNameURL := acctest.BootstrapComputeStoragePool(t, "basic-1", "hyperdisk-balanced") - storagePoolResourceName, err := extractSPName(storagePoolNameURL) - if err != nil { - t.Fatal("Failed to extract Storage Pool resource name from URL.") - } + storagePoolResourceName := acctest.BootstrapComputeStoragePool(t, "basic-1", "hyperdisk-balanced") + acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), @@ -4813,10 +4806,10 @@ resource "google_container_node_pool" "np" { initial_node_count = 2 node_config { - machine_type = "c3-standard-4" - disk_size_gb = 50 - disk_type = "hyperdisk-balanced" - storage_pools = ["%[5]s"] + machine_type = "c3-standard-4" + disk_size_gb = 50 + disk_type = "hyperdisk-balanced" + storage_pools = ["%[5]s"] } } `, cluster, np, networkName, subnetworkName, storagePoolResourceName, location)