Skip to content

Commit

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

* fix whitespace consistency

* remove whitespace
  • Loading branch information
BBBmau authored and kapreus committed Jan 2, 2024
1 parent 2543ec5 commit 122892a
Showing 1 changed file with 38 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,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 @@ -50,14 +52,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 @@ -78,7 +82,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 @@ -111,17 +116,17 @@ func TestAccComputeNetwork_routingModeAndUpdate(t *testing.T) {
func TestAccComputeNetwork_numericId(t *testing.T) {
t.Parallel()
suffixName := acctest.RandString(t, 10)
networkName := fmt.Sprintf("tf-test-network-basic-%s", suffixName)
projectId := envvar.GetTestProjectFromEnv()
networkId := fmt.Sprintf("projects/%v/global/networks/%v", projectId, networkName)
networkName := fmt.Sprintf("tf-test-network-basic-%s", suffixName)
projectId := envvar.GetTestProjectFromEnv()
networkId := fmt.Sprintf("projects/%v/global/networks/%v", projectId, networkName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(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 @@ -140,6 +145,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 @@ -149,7 +156,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 @@ -165,14 +172,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 @@ -189,7 +198,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 @@ -401,56 +411,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 122892a

Please sign in to comment.