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 #19646

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
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/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/services/container/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down Expand Up @@ -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) },
Expand Down Expand Up @@ -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()

Expand Down
21 changes: 7 additions & 14 deletions google/services/container/resource_container_node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down