mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-01 07:42:40 +00:00
Updated google_bigtable_table tests.
This commit is contained in:
parent
a358f4147f
commit
e5ff2b7bcd
|
@ -64,11 +64,15 @@ func resourceBigtableTableCreate(d *schema.ResourceData, meta interface{}) error
|
|||
name := d.Get("name").(string)
|
||||
if v, ok := d.GetOk("split_keys"); ok {
|
||||
splitKeys := convertSchemaArrayToStringArray(v.([]interface{}))
|
||||
// This method may return before the table's creation is complete - we may need to wait until
|
||||
// it exists in the future.
|
||||
err = c.CreatePresplitTable(ctx, name, splitKeys)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating presplit table. %s", err)
|
||||
}
|
||||
} else {
|
||||
// This method may return before the table's creation is complete - we may need to wait until
|
||||
// it exists in the future.
|
||||
err = c.CreateTable(ctx, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating table. %s", err)
|
||||
|
@ -128,7 +132,7 @@ func resourceBigtableTableDestroy(d *schema.ResourceData, meta interface{}) erro
|
|||
name := d.Get("name").(string)
|
||||
err = c.DeleteTable(ctx, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting instance. %s", err)
|
||||
return fmt.Errorf("Error deleting table. %s", err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
|
|
@ -30,6 +30,26 @@ func TestAccBigtableTable_basic(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccBigtableTable_splitKeys(t *testing.T) {
|
||||
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 {
|
||||
|
@ -44,21 +64,8 @@ func testAccCheckBigtableTableDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
tables, err := c.Tables(ctx)
|
||||
if err != nil {
|
||||
// The instance is already gone.
|
||||
return nil
|
||||
}
|
||||
|
||||
found := false
|
||||
for _, t := range tables {
|
||||
if t == rs.Primary.Attributes["name"] {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
_, 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"])
|
||||
}
|
||||
|
||||
|
@ -85,20 +92,8 @@ func testAccBigtableTableExists(n string) resource.TestCheckFunc {
|
|||
return fmt.Errorf("Error starting admin client. %s", err)
|
||||
}
|
||||
|
||||
tables, err := c.Tables(ctx)
|
||||
_, err = c.TableInfo(ctx, rs.Primary.Attributes["name"])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error starting admin client. %s", err)
|
||||
}
|
||||
|
||||
found := false
|
||||
for _, t := range tables {
|
||||
if t == rs.Primary.Attributes["name"] {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
return fmt.Errorf("Error retrieving table. Could not find %s in %s.", rs.Primary.Attributes["name"], rs.Primary.Attributes["instance_name"])
|
||||
}
|
||||
|
||||
|
@ -118,6 +113,23 @@ resource "google_bigtable_instance" "instance" {
|
|||
storage_type = "HDD"
|
||||
}
|
||||
|
||||
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"
|
||||
num_nodes = 3
|
||||
storage_type = "HDD"
|
||||
}
|
||||
|
||||
resource "google_bigtable_table" "table" {
|
||||
name = "%s"
|
||||
instance_name = "${google_bigtable_instance.instance.name}"
|
||||
|
|
Loading…
Reference in New Issue
Block a user