terraform-provider-google/google/resource_firestore_index_generated_test.go
The Magician 6e57eff780 Add support for Firestore Index (#3484)
Signed-off-by: Modular Magician <magic-modules@google.com>
2019-04-25 10:12:48 -07:00

102 lines
2.4 KiB
Go

// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------
package google
import (
"fmt"
"strings"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccFirestoreIndex_firestoreIndexBasicExample(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"project_id": getTestFirestoreProjectFromEnv(t),
"random_suffix": acctest.RandString(10),
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFirestoreIndexDestroy,
Steps: []resource.TestStep{
{
Config: testAccFirestoreIndex_firestoreIndexBasicExample(context),
},
{
ResourceName: "google_firestore_index.my-index",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"database", "collection"},
},
},
})
}
func testAccFirestoreIndex_firestoreIndexBasicExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_firestore_index" "my-index" {
project = "%{project_id}"
collection = "chatrooms"
fields {
field_path = "name"
order = "ASCENDING"
}
fields {
field_path = "description"
order = "DESCENDING"
}
fields {
field_path = "__name__"
order = "DESCENDING"
}
}
`, context)
}
func testAccCheckFirestoreIndexDestroy(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_firestore_index" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}
config := testAccProvider.Meta().(*Config)
url, err := replaceVarsForTest(rs, "https://firestore.googleapis.com/v1/{{name}}")
if err != nil {
return err
}
_, err = sendRequest(config, "GET", url, nil)
if err == nil {
return fmt.Errorf("FirestoreIndex still exists at %s", url)
}
}
return nil
}