mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 17:16:44 +00:00
![Evan Brown](/assets/img/avatar_default.png)
Acceptance tests for Pubsub topics and subscriptions failed after incorrectly determining that resources were not deleted in the CheckDestroy phase. Fixes 5437
70 lines
1.6 KiB
Go
70 lines
1.6 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 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)
|
|
topic, _ := config.clientPubsub.Projects.Topics.Get(rs.Primary.ID).Do()
|
|
if topic != nil {
|
|
return fmt.Errorf("Topic still present")
|
|
}
|
|
}
|
|
|
|
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 {
|
|
return fmt.Errorf("Topic does not exist")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
var testAccPubsubTopic = fmt.Sprintf(`
|
|
resource "google_pubsub_topic" "foobar" {
|
|
name = "pstopic-test-%s"
|
|
}`, acctest.RandString(10))
|