mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-06 02:31:05 +00:00
4b77dca918
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).
142 lines
3.7 KiB
Go
142 lines
3.7 KiB
Go
package google
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccBigtableTable_basic(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
tableName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckBigtableTableDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccBigtableTable(instanceName, tableName),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccBigtableTableExists(
|
|
"google_bigtable_table.table"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccBigtableTable_splitKeys(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
tableName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckBigtableTableDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccBigtableTable_splitKeys(instanceName, tableName),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccBigtableTableExists(
|
|
"google_bigtable_table.table"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckBigtableTableDestroy(s *terraform.State) error {
|
|
var ctx = context.Background()
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "google_bigtable_table" {
|
|
continue
|
|
}
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
c, err := config.bigtableClientFactory.NewAdminClient(config.Project, rs.Primary.Attributes["instance_name"])
|
|
if err != nil {
|
|
// The instance is already gone
|
|
return nil
|
|
}
|
|
|
|
_, err = c.TableInfo(ctx, rs.Primary.Attributes["name"])
|
|
if err == nil {
|
|
return fmt.Errorf("Table still present. Found %s in %s.", rs.Primary.Attributes["name"], rs.Primary.Attributes["instance_name"])
|
|
}
|
|
|
|
c.Close()
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testAccBigtableTableExists(n string) resource.TestCheckFunc {
|
|
var ctx = context.Background()
|
|
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)
|
|
c, err := config.bigtableClientFactory.NewAdminClient(config.Project, rs.Primary.Attributes["instance_name"])
|
|
if err != nil {
|
|
return fmt.Errorf("Error starting admin client. %s", err)
|
|
}
|
|
|
|
_, err = c.TableInfo(ctx, rs.Primary.Attributes["name"])
|
|
if err != nil {
|
|
return fmt.Errorf("Error retrieving table. Could not find %s in %s.", rs.Primary.Attributes["name"], rs.Primary.Attributes["instance_name"])
|
|
}
|
|
|
|
c.Close()
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccBigtableTable(instanceName, tableName string) string {
|
|
return fmt.Sprintf(`
|
|
resource "google_bigtable_instance" "instance" {
|
|
name = "%s"
|
|
cluster_id = "%s"
|
|
zone = "us-central1-b"
|
|
instance_type = "DEVELOPMENT"
|
|
}
|
|
|
|
resource "google_bigtable_table" "table" {
|
|
name = "%s"
|
|
instance_name = "${google_bigtable_instance.instance.name}"
|
|
}
|
|
`, instanceName, instanceName, tableName)
|
|
}
|
|
|
|
func testAccBigtableTable_splitKeys(instanceName, tableName string) string {
|
|
return fmt.Sprintf(`
|
|
resource "google_bigtable_instance" "instance" {
|
|
name = "%s"
|
|
cluster_id = "%s"
|
|
zone = "us-central1-b"
|
|
instance_type = "DEVELOPMENT"
|
|
}
|
|
|
|
resource "google_bigtable_table" "table" {
|
|
name = "%s"
|
|
instance_name = "${google_bigtable_instance.instance.name}"
|
|
split_keys = ["a", "b", "c"]
|
|
}
|
|
`, instanceName, instanceName, tableName)
|
|
}
|