2015-10-28 18:55:50 +01:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2015-10-28 18:55:50 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccPubsubTopicCreate(t *testing.T) {
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckPubsubTopicDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccPubsubTopic,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccPubsubTopicExists(
|
|
|
|
"google_pubsub_topic.foobar"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03 00:36:32 +01:00
|
|
|
topic, _ := config.clientPubsub.Projects.Topics.Get(rs.Primary.ID).Do()
|
|
|
|
if topic != nil {
|
2016-02-13 07:39:23 +01:00
|
|
|
return fmt.Errorf("Topic still present")
|
2015-10-28 18:55:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccPubsubTopicExists(n string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No ID is set")
|
|
|
|
}
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
_, err := config.clientPubsub.Projects.Topics.Get(rs.Primary.ID).Do()
|
|
|
|
if err != nil {
|
2016-03-03 00:36:32 +01:00
|
|
|
return fmt.Errorf("Topic does not exist")
|
2015-10-28 18:55:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccPubsubTopic = fmt.Sprintf(`
|
2015-10-28 18:55:50 +01:00
|
|
|
resource "google_pubsub_topic" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "pstopic-test-%s"
|
|
|
|
}`, acctest.RandString(10))
|