Skip to content

Commit

Permalink
fixed pubsublite update issues (GoogleCloudPlatform#4954)
Browse files Browse the repository at this point in the history
* fixed pubsublite update issues

* add tests
  • Loading branch information
edwardmedia authored and khajduczenia committed Oct 12, 2021
1 parent 2600331 commit 6f1163c
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mmv1/products/pubsublite/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ objects:
create_url: projects/{{project}}/locations/{{zone}}/topics?topicId={{name}}
update_verb: :PATCH
update_mask: true
update_url: projects/{{project}}/locations/{{zone}}/topics/{name}}
update_url: projects/{{project}}/locations/{{zone}}/topics/{{name}}
parameters:
- !ruby/object:Api::Type::String
name: region
Expand Down Expand Up @@ -111,7 +111,7 @@ objects:
create_url: projects/{{project}}/locations/{{zone}}/subscriptions?subscriptionId={{name}}
update_verb: :PATCH
update_mask: true
update_url: projects/{{project}}/locations/{{zone}}/subscriptions/{name}}
update_url: projects/{{project}}/locations/{{zone}}/subscriptions/{{name}}
parameters:
- !ruby/object:Api::Type::String
name: region
Expand All @@ -136,7 +136,7 @@ objects:
A reference to a Topic resource.
required: true
input: true
pattern: 'projects/{{project}}/locations/{{zone}}/topics/{name}}'
pattern: 'projects/{{project}}/locations/{{zone}}/topics/{{name}}'
- !ruby/object:Api::Type::NestedObject
name: 'deliveryConfig'
description: |
Expand Down
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 6f1163c

Please sign in to comment.