terraform-provider-google/google/resource_compute_route_test.go
Joe Selman 4b77dca918 Revert "Revert "Add t.Parallel to all acceptance tests (#558)""
This reverts commit 8ab9d96d25 and revives
the original commit that adds t.Parallel to all acceptance tests. It
turns out test failures were unrelated to this change (rather, they were
related to quota issues).
2017-10-12 15:07:29 -07:00

141 lines
3.4 KiB
Go

package google
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"google.golang.org/api/compute/v1"
)
func TestAccComputeRoute_basic(t *testing.T) {
t.Parallel()
var route compute.Route
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeRouteDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeRoute_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeRouteExists(
"google_compute_route.foobar", &route),
),
},
},
})
}
func TestAccComputeRoute_defaultInternetGateway(t *testing.T) {
t.Parallel()
var route compute.Route
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeRouteDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeRoute_defaultInternetGateway,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeRouteExists(
"google_compute_route.foobar", &route),
),
},
},
})
}
func testAccCheckComputeRouteDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_route" {
continue
}
_, err := config.clientCompute.Routes.Get(
config.Project, rs.Primary.ID).Do()
if err == nil {
return fmt.Errorf("Route still exists")
}
}
return nil
}
func testAccCheckComputeRouteExists(n string, route *compute.Route) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
config := testAccProvider.Meta().(*Config)
found, err := config.clientCompute.Routes.Get(
config.Project, rs.Primary.ID).Do()
if err != nil {
return err
}
if found.Name != rs.Primary.ID {
return fmt.Errorf("Route not found")
}
*route = *found
return nil
}
}
var testAccComputeRoute_basic = fmt.Sprintf(`
resource "google_compute_network" "foobar" {
name = "route-test-%s"
}
resource "google_compute_subnetwork" "foobar" {
name = "route-test-%s"
ip_cidr_range = "10.0.0.0/16"
network = "${google_compute_network.foobar.self_link}"
region = "us-central1"
}
resource "google_compute_route" "foobar" {
name = "route-test-%s"
dest_range = "15.0.0.0/24"
network = "${google_compute_network.foobar.name}"
next_hop_ip = "10.154.0.1"
priority = 100
}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
var testAccComputeRoute_defaultInternetGateway = fmt.Sprintf(`
resource "google_compute_network" "foobar" {
name = "route-test-%s"
}
resource "google_compute_subnetwork" "foobar" {
name = "route-test-%s"
ip_cidr_range = "10.0.0.0/16"
network = "${google_compute_network.foobar.self_link}"
region = "us-central1"
}
resource "google_compute_route" "foobar" {
name = "route-test-%s"
dest_range = "0.0.0.0/0"
network = "${google_compute_network.foobar.name}"
next_hop_gateway = "default-internet-gateway"
priority = 100
}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))