mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 09:06:44 +00:00
![Joe Selman](/assets/img/avatar_default.png)
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).
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
package google
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccGoogleComputeZones_basic(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCheckGoogleComputeZonesConfig,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckGoogleComputeZonesMeta("data.google_compute_zones.available"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckGoogleComputeZonesMeta(n string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Can't find zones data source: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return errors.New("zones data source ID not set.")
|
|
}
|
|
|
|
count, ok := rs.Primary.Attributes["names.#"]
|
|
if !ok {
|
|
return errors.New("can't find 'names' attribute")
|
|
}
|
|
|
|
noOfNames, err := strconv.Atoi(count)
|
|
if err != nil {
|
|
return errors.New("failed to read number of zones")
|
|
}
|
|
if noOfNames < 2 {
|
|
return fmt.Errorf("expected at least 2 zones, received %d, this is most likely a bug",
|
|
noOfNames)
|
|
}
|
|
|
|
for i := 0; i < noOfNames; i++ {
|
|
idx := "names." + strconv.Itoa(i)
|
|
v, ok := rs.Primary.Attributes[idx]
|
|
if !ok {
|
|
return fmt.Errorf("zone list is corrupt (%q not found), this is definitely a bug", idx)
|
|
}
|
|
if len(v) < 1 {
|
|
return fmt.Errorf("Empty zone name (%q), this is definitely a bug", idx)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
var testAccCheckGoogleComputeZonesConfig = `
|
|
data "google_compute_zones" "available" {}
|
|
`
|