github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/google/resource_pubsub_topic_test.go (about) 1 package google 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 func TestAccPubsubTopicCreate(t *testing.T) { 12 13 resource.Test(t, resource.TestCase{ 14 PreCheck: func() { testAccPreCheck(t) }, 15 Providers: testAccProviders, 16 CheckDestroy: testAccCheckPubsubTopicDestroy, 17 Steps: []resource.TestStep{ 18 resource.TestStep{ 19 Config: testAccPubsubTopic, 20 Check: resource.ComposeTestCheckFunc( 21 testAccPubsubTopicExists( 22 "google_pubsub_topic.foobar"), 23 ), 24 }, 25 }, 26 }) 27 } 28 29 func testAccCheckPubsubTopicDestroy(s *terraform.State) error { 30 for _, rs := range s.RootModule().Resources { 31 if rs.Type != "google_pubsub_topic" { 32 continue 33 } 34 35 config := testAccProvider.Meta().(*Config) 36 _, err := config.clientPubsub.Projects.Topics.Get(rs.Primary.ID).Do() 37 if err != nil { 38 fmt.Errorf("Topic still present") 39 } 40 } 41 42 return nil 43 } 44 45 func testAccPubsubTopicExists(n string) resource.TestCheckFunc { 46 return func(s *terraform.State) error { 47 rs, ok := s.RootModule().Resources[n] 48 if !ok { 49 return fmt.Errorf("Not found: %s", n) 50 } 51 52 if rs.Primary.ID == "" { 53 return fmt.Errorf("No ID is set") 54 } 55 config := testAccProvider.Meta().(*Config) 56 _, err := config.clientPubsub.Projects.Topics.Get(rs.Primary.ID).Do() 57 if err != nil { 58 fmt.Errorf("Topic still present") 59 } 60 61 return nil 62 } 63 } 64 65 const testAccPubsubTopic = ` 66 resource "google_pubsub_topic" "foobar" { 67 name = "foobar" 68 }`