Skip to content

Commit

Permalink
container: fix storage pool resource names in test (GoogleCloudPlatfo…
Browse files Browse the repository at this point in the history
  • Loading branch information
wyardley authored and anavada committed Sep 30, 2024
1 parent 227a05e commit 55c0983
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 36 deletions.
9 changes: 8 additions & 1 deletion mmv1/third_party/terraform/acctest/bootstrap_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11697,11 +11697,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) },
Expand Down Expand Up @@ -11754,11 +11750,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) },
Expand Down Expand Up @@ -11800,17 +11792,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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4960,11 +4960,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) },
Expand Down Expand Up @@ -5024,11 +5020,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),
Expand Down Expand Up @@ -5084,10 +5077,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)
Expand Down

0 comments on commit 55c0983

Please sign in to comment.