Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardmedia committed Jul 9, 2021
1 parent 6a1193d commit da83fa6
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccPubsubLiteSubscription_pubsubLiteSubscription_deliveryRequirement_update(t *testing.T) {
t.Parallel()

topic := fmt.Sprintf("tf-test-topic-foo-%s", randString(t, 10))
subscription := fmt.Sprintf("tf-test-topic-foo-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPubsubLiteSubscriptionDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccPubsubLiteSubscription_pubsubLiteSubscription_deliveryRequirement_update(topic, subscription, "DELIVER_AFTER_STORED"),
},
{
ResourceName: "google_pubsub_lite_subscription.example",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"topic", "region", "zone", "name"},
},
{
Config: testAccPubsubLiteSubscription_pubsubLiteSubscription_deliveryRequirement_update(topic, subscription, "DELIVER_IMMEDIATELY"),
},
{
ResourceName: "google_pubsub_lite_subscription.example",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"topic", "region", "zone", "name"},
},
},
})
}

func testAccPubsubLiteSubscription_pubsubLiteSubscription_deliveryRequirement_update(topic, subscription, delivery string) string {
return fmt.Sprintf(`
resource "google_pubsub_lite_topic" "example" {
name = "%s"
partition_config {
count = 1
capacity {
publish_mib_per_sec = 4
subscribe_mib_per_sec = 8
}
}
retention_config {
per_partition_bytes = 32212254720
}
}
resource "google_pubsub_lite_subscription" "example" {
name = "%s"
topic = google_pubsub_lite_topic.example.name
delivery_config {
delivery_requirement = "%s"
}
}
`, topic, subscription, delivery)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccPubsubLiteTopic_pubsubLiteTopic_count_update(t *testing.T) {
t.Parallel()

topic := fmt.Sprintf("tf-test-topic-foo-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPubsubLiteTopicDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccPubsubLiteTopic_pubsubLiteTopic_count_update(topic, "1"),
},
{
ResourceName: "google_pubsub_lite_topic.example",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region", "zone", "name"},
},
{
Config: testAccPubsubLiteTopic_pubsubLiteTopic_count_update(topic, "2"),
},
{
ResourceName: "google_pubsub_lite_topic.example",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region", "zone", "name"},
},
},
})
}

func testAccPubsubLiteTopic_pubsubLiteTopic_count_update(topic, count string) string {
return fmt.Sprintf(`
resource "google_pubsub_lite_topic" "example" {
name = "%s"
partition_config {
count = %s
capacity {
publish_mib_per_sec = 4
subscribe_mib_per_sec = 8
}
}
retention_config {
per_partition_bytes = 32212254720
}
}
`, topic, count)
}

0 comments on commit da83fa6

Please sign in to comment.