mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 09:06:44 +00:00
58 lines
1.3 KiB
Go
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)
|
|
}
|