2015-10-28 17:55:50 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2016-01-05 21:47:10 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2015-10-28 17:55:50 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2018-02-20 19:12:22 +00:00
|
|
|
func TestAccPubsubTopic_basic(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
2015-10-28 17:55:50 +00:00
|
|
|
|
2018-02-20 19:12:22 +00:00
|
|
|
topicName := acctest.RandomWithPrefix("tf-test-topic")
|
|
|
|
|
2015-10-28 17:55:50 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckPubsubTopicDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2018-02-20 19:12:22 +00:00
|
|
|
Config: testAccPubsubTopic_basic(topicName),
|
|
|
|
},
|
2018-03-02 19:22:58 +00:00
|
|
|
// Check importing with just the topic name
|
2018-02-20 19:12:22 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_pubsub_topic.foo",
|
|
|
|
ImportStateId: topicName,
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"force_destroy"},
|
2015-10-28 17:55:50 +00:00
|
|
|
},
|
2018-03-02 19:22:58 +00:00
|
|
|
// Check importing with the full resource id
|
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_pubsub_topic.foo",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"force_destroy"},
|
|
|
|
},
|
2015-10-28 17:55:50 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckPubsubTopicDestroy(s *terraform.State) error {
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "google_pubsub_topic" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
2016-03-02 23:36:32 +00:00
|
|
|
topic, _ := config.clientPubsub.Projects.Topics.Get(rs.Primary.ID).Do()
|
|
|
|
if topic != nil {
|
2016-02-13 06:39:23 +00:00
|
|
|
return fmt.Errorf("Topic still present")
|
2015-10-28 17:55:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-20 19:12:22 +00:00
|
|
|
func testAccPubsubTopic_basic(name string) string {
|
2017-11-28 00:32:00 +00:00
|
|
|
return fmt.Sprintf(`
|
2018-02-20 19:12:22 +00:00
|
|
|
resource "google_pubsub_topic" "foo" {
|
|
|
|
name = "%s"
|
|
|
|
}`, name)
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|