terraform-provider-google/google/resource_pubsub_topic_test.go
Vincent Roseberry 297b0a80e0
Refactor PubSub import test (#1106)
* Refactor pubsub subscription import test

* Refactor pubsub topic import test
2018-02-20 11:12:22 -08:00

58 lines
1.3 KiB
Go

package google
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccPubsubTopic_basic(t *testing.T) {
t.Parallel()
topicName := acctest.RandomWithPrefix("tf-test-topic")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPubsubTopicDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccPubsubTopic_basic(topicName),
},
resource.TestStep{
ResourceName: "google_pubsub_topic.foo",
ImportStateId: topicName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
},
})
}
func testAccCheckPubsubTopicDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_pubsub_topic" {
continue
}
config := testAccProvider.Meta().(*Config)
topic, _ := config.clientPubsub.Projects.Topics.Get(rs.Primary.ID).Do()
if topic != nil {
return fmt.Errorf("Topic still present")
}
}
return nil
}
func testAccPubsubTopic_basic(name string) string {
return fmt.Sprintf(`
resource "google_pubsub_topic" "foo" {
name = "%s"
}`, name)
}