Skip to content

Commit

Permalink
container: fix storage pool resource names in test (#11832) (#8290)
Browse files Browse the repository at this point in the history
[upstream:8817cecb1e2562ca433901e50abfbc530b3f3f9e]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 26, 2024
1 parent 3fe1977 commit a9c70ad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .changelog/11832.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
9 changes: 8 additions & 1 deletion google-beta/acctest/bootstrap_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 2 additions & 21 deletions google-beta/services/container/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11645,11 +11645,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 @@ -11702,11 +11698,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 @@ -11748,17 +11740,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 @@ -4942,11 +4942,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 @@ -5005,11 +5001,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 @@ -5065,10 +5058,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 a9c70ad

Please sign in to comment.