|
| 1 | +package google |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 7 | +) |
| 8 | + |
| 9 | +func TestAccDataSourceGooglePubsubSubscription_basic(t *testing.T) { |
| 10 | + t.Parallel() |
| 11 | + |
| 12 | + context := map[string]interface{}{ |
| 13 | + "random_suffix": randString(t, 10), |
| 14 | + } |
| 15 | + |
| 16 | + vcrTest(t, resource.TestCase{ |
| 17 | + PreCheck: func() { testAccPreCheck(t) }, |
| 18 | + Providers: testAccProviders, |
| 19 | + CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t), |
| 20 | + Steps: []resource.TestStep{ |
| 21 | + { |
| 22 | + Config: testAccDataSourceGooglePubsubSubscription_basic(context), |
| 23 | + Check: resource.ComposeTestCheckFunc( |
| 24 | + checkDataSourceStateMatchesResourceState("data.google_pubsub_subscription.foo", "google_pubsub_subscription.foo"), |
| 25 | + ), |
| 26 | + }, |
| 27 | + }, |
| 28 | + }) |
| 29 | +} |
| 30 | + |
| 31 | +func TestAccDataSourceGooglePubsubSubscription_optionalProject(t *testing.T) { |
| 32 | + t.Parallel() |
| 33 | + |
| 34 | + context := map[string]interface{}{ |
| 35 | + "random_suffix": randString(t, 10), |
| 36 | + } |
| 37 | + |
| 38 | + vcrTest(t, resource.TestCase{ |
| 39 | + PreCheck: func() { testAccPreCheck(t) }, |
| 40 | + Providers: testAccProviders, |
| 41 | + CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t), |
| 42 | + Steps: []resource.TestStep{ |
| 43 | + { |
| 44 | + Config: testAccDataSourceGooglePubsubSubscription_optionalProject(context), |
| 45 | + Check: resource.ComposeTestCheckFunc( |
| 46 | + checkDataSourceStateMatchesResourceState("data.google_pubsub_subscription.foo", "google_pubsub_subscription.foo"), |
| 47 | + ), |
| 48 | + }, |
| 49 | + }, |
| 50 | + }) |
| 51 | +} |
| 52 | + |
| 53 | +func testAccDataSourceGooglePubsubSubscription_basic(context map[string]interface{}) string { |
| 54 | + return Nprintf(` |
| 55 | +resource "google_pubsub_topic" "foo" { |
| 56 | + name = "tf-test-pubsub-%{random_suffix}" |
| 57 | +} |
| 58 | +
|
| 59 | +resource "google_pubsub_subscription" "foo" { |
| 60 | + name = "tf-test-pubsub-subscription-%{random_suffix}" |
| 61 | + topic = google_pubsub_topic.foo.name |
| 62 | +} |
| 63 | +
|
| 64 | +data "google_pubsub_subscription" "foo" { |
| 65 | + name = google_pubsub_subscription.foo.name |
| 66 | + project = google_pubsub_subscription.foo.project |
| 67 | +} |
| 68 | +`, context) |
| 69 | +} |
| 70 | + |
| 71 | +func testAccDataSourceGooglePubsubSubscription_optionalProject(context map[string]interface{}) string { |
| 72 | + return Nprintf(` |
| 73 | +resource "google_pubsub_topic" "foo" { |
| 74 | + name = "tf-test-pubsub-%{random_suffix}" |
| 75 | +} |
| 76 | +
|
| 77 | +resource "google_pubsub_subscription" "foo" { |
| 78 | + name = "tf-test-pubsub-subscription-%{random_suffix}" |
| 79 | + topic = google_pubsub_topic.foo.name |
| 80 | +} |
| 81 | +
|
| 82 | +data "google_pubsub_subscription" "foo" { |
| 83 | + name = google_pubsub_subscription.foo.name |
| 84 | +} |
| 85 | +`, context) |
| 86 | +} |
0 commit comments