Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container: fix storage pool resource names in test #11832

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[^"]+)`)
wyardley marked this conversation as resolved.
Show resolved Hide resolved
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
Loading