Skip to content

Commit

Permalink
Refactor networkName in TestAccComputeNetwork_* (#9713) (#16891)
Browse files Browse the repository at this point in the history
* refactor networkName in tfconfig compute_network

* fix whitespace consistency

* remove whitespace
[upstream:12e1fba192e0eca55baadff3e126bef8371e65a8]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jan 2, 2024
1 parent badc26b commit cf66153
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .changelog/9713.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
60 changes: 35 additions & 25 deletions google/services/compute/resource_compute_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ func TestAccComputeNetwork_explicitAutoSubnet(t *testing.T) {
t.Parallel()

var network compute.Network
suffixName := acctest.RandString(t, 10)
networkName := fmt.Sprintf("tf-test-network-basic-%s", suffixName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeNetwork_basic(acctest.RandString(t, 10)),
Config: testAccComputeNetwork_basic(networkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeNetworkExists(
t, "google_compute_network.bar", &network),
Expand All @@ -47,14 +49,16 @@ func TestAccComputeNetwork_customSubnet(t *testing.T) {
t.Parallel()

var network compute.Network
suffixName := acctest.RandString(t, 10)
networkName := fmt.Sprintf("tf-test-network-custom-sn-%s", suffixName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeNetwork_custom_subnet(acctest.RandString(t, 10)),
Config: testAccComputeNetwork_custom_subnet(networkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeNetworkExists(
t, "google_compute_network.baz", &network),
Expand All @@ -75,7 +79,8 @@ func TestAccComputeNetwork_routingModeAndUpdate(t *testing.T) {
t.Parallel()

var network compute.Network
networkName := acctest.RandString(t, 10)
suffixName := acctest.RandString(t, 10)
networkName := fmt.Sprintf("tf-test-network-routing-mode-%s", suffixName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
Expand Down Expand Up @@ -118,7 +123,7 @@ func TestAccComputeNetwork_numericId(t *testing.T) {
CheckDestroy: testAccCheckComputeNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeNetwork_basic(suffixName),
Config: testAccComputeNetwork_basic(networkName),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("google_compute_network.bar", "numeric_id", regexp.MustCompile("^\\d{1,}$")),
resource.TestCheckResourceAttr("google_compute_network.bar", "id", networkId),
Expand All @@ -137,6 +142,8 @@ func TestAccComputeNetwork_default_routing_mode(t *testing.T) {
t.Parallel()

var network compute.Network
suffixName := acctest.RandString(t, 10)
networkName := fmt.Sprintf("tf-test-network-network-default-routes-%s", suffixName)

expectedRoutingMode := "REGIONAL"

Expand All @@ -146,7 +153,7 @@ func TestAccComputeNetwork_default_routing_mode(t *testing.T) {
CheckDestroy: testAccCheckComputeNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeNetwork_basic(acctest.RandString(t, 10)),
Config: testAccComputeNetwork_basic(networkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeNetworkExists(
t, "google_compute_network.bar", &network),
Expand All @@ -162,14 +169,16 @@ func TestAccComputeNetwork_networkDeleteDefaultRoute(t *testing.T) {
t.Parallel()

var network compute.Network
suffixName := acctest.RandString(t, 10)
networkName := fmt.Sprintf("tf-test-network-network-default-routes-%s", suffixName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeNetwork_deleteDefaultRoute(acctest.RandString(t, 10)),
Config: testAccComputeNetwork_deleteDefaultRoute(networkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeNetworkExists(
t, "google_compute_network.bar", &network),
Expand All @@ -186,7 +195,8 @@ func TestAccComputeNetwork_networkFirewallPolicyEnforcementOrderAndUpdate(t *tes

var network compute.Network
var updatedNetwork compute.Network
networkName := acctest.RandString(t, 10)
suffixName := acctest.RandString(t, 10)
networkName := fmt.Sprintf("tf-test-network-firewall-policy-enforcement-order-%s", suffixName)

defaultNetworkFirewallPolicyEnforcementOrder := "AFTER_CLASSIC_FIREWALL"
explicitNetworkFirewallPolicyEnforcementOrder := "BEFORE_CLASSIC_FIREWALL"
Expand Down Expand Up @@ -398,56 +408,56 @@ func testAccCheckComputeNetworkWasUpdated(newNetwork *compute.Network, oldNetwor
}
}

func testAccComputeNetwork_basic(suffix string) string {
func testAccComputeNetwork_basic(networkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "bar" {
name = "tf-test-network-basic-%s"
name = "%s"
auto_create_subnetworks = true
}
`, suffix)
`, networkName)
}

func testAccComputeNetwork_custom_subnet(suffix string) string {
func testAccComputeNetwork_custom_subnet(networkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "baz" {
name = "tf-test-network-custom-sn-%s"
name = "%s"
auto_create_subnetworks = false
}
`, suffix)
`, networkName)
}

func testAccComputeNetwork_routing_mode(network, routingMode string) string {
func testAccComputeNetwork_routing_mode(networkName, routingMode string) string {
return fmt.Sprintf(`
resource "google_compute_network" "acc_network_routing_mode" {
name = "tf-test-network-routing-mode-%s"
name = "%s"
routing_mode = "%s"
}
`, network, routingMode)
`, networkName, routingMode)
}

func testAccComputeNetwork_deleteDefaultRoute(suffix string) string {
func testAccComputeNetwork_deleteDefaultRoute(networkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "bar" {
name = "tf-test-network-delete-default-routes-%s"
name = "%s"
delete_default_routes_on_create = true
auto_create_subnetworks = false
}
`, suffix)
`, networkName)
}

func testAccComputeNetwork_networkFirewallPolicyEnforcementOrderDefault(network string) string {
func testAccComputeNetwork_networkFirewallPolicyEnforcementOrderDefault(networkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "acc_network_firewall_policy_enforcement_order" {
name = "tf-test-network-firewall-policy-enforcement-order-%s"
name = "%s"
}
`, network)
`, networkName)
}

func testAccComputeNetwork_networkFirewallPolicyEnforcementOrderUpdate(network, order string) string {
func testAccComputeNetwork_networkFirewallPolicyEnforcementOrderUpdate(networkName, order string) string {
return fmt.Sprintf(`
resource "google_compute_network" "acc_network_firewall_policy_enforcement_order" {
name = "tf-test-network-firewall-policy-enforcement-order-%s"
name = "%s"
network_firewall_policy_enforcement_order = "%s"
}
`, network, order)
`, networkName, order)
}

0 comments on commit cf66153

Please sign in to comment.