terraform-provider-google/google/resource_pubsub_topic_generated_test.go
The Magician 2950923ee6 Generate Pubsub Topics/Subscriptions with MM (+add labels) (#3043)
<!-- This change is generated by MagicModules. -->
/cc @drebes
2019-02-19 15:10:44 -08:00

87 lines
2.1 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 TestAccPubsubTopic_pubsubTopicBasicExample(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"random_suffix": acctest.RandString(10),
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPubsubTopicDestroy,
Steps: []resource.TestStep{
{
Config: testAccPubsubTopic_pubsubTopicBasicExample(context),
},
{
ResourceName: "google_pubsub_topic.example",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func testAccPubsubTopic_pubsubTopicBasicExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_pubsub_topic" "example" {
name = "example-topic-%{random_suffix}"
labels = {
foo = "bar"
}
}
`, context)
}
func testAccCheckPubsubTopicDestroy(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_pubsub_topic" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}
config := testAccProvider.Meta().(*Config)
url, err := replaceVarsForTest(rs, "https://pubsub.googleapis.com/v1/projects/{{project}}/topics/{{name}}")
if err != nil {
return err
}
_, err = sendRequest(config, "GET", url, nil)
if err == nil {
return fmt.Errorf("PubsubTopic still exists at %s", url)
}
}
return nil
}