@@ -400,6 +400,47 @@ func TestUnitPubsubSubscription_IgnoreMissingKeyInMap(t *testing.T) {
400400 }
401401}
402402
403+ func TestAccPubsubSubscription_filter (t * testing.T ) {
404+ t .Parallel ()
405+
406+ topic := fmt .Sprintf ("tf-test-topic-%s" , acctest .RandString (t , 10 ))
407+ subscriptionShort := fmt .Sprintf ("tf-test-sub-%s" , acctest .RandString (t , 10 ))
408+
409+ acctest .VcrTest (t , resource.TestCase {
410+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
411+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
412+ CheckDestroy : testAccCheckPubsubSubscriptionDestroyProducer (t ),
413+ Steps : []resource.TestStep {
414+ {
415+ Config : testAccPubsubSubscription_filter (topic , subscriptionShort , "attributes.foo = \\ \" bar\\ \" " ),
416+ Check : resource .ComposeTestCheckFunc (
417+ // Test schema
418+ resource .TestCheckResourceAttr ("google_pubsub_subscription.foo" , "filter" , "attributes.foo = \" bar\" " ),
419+ ),
420+ },
421+ {
422+ ResourceName : "google_pubsub_subscription.foo" ,
423+ ImportStateId : subscriptionShort ,
424+ ImportState : true ,
425+ ImportStateVerify : true ,
426+ },
427+ {
428+ Config : testAccPubsubSubscription_filter (topic , subscriptionShort , "" ),
429+ Check : resource .ComposeTestCheckFunc (
430+ // Test schema
431+ resource .TestCheckResourceAttr ("google_pubsub_subscription.foo" , "filter" , "" ),
432+ ),
433+ },
434+ {
435+ ResourceName : "google_pubsub_subscription.foo" ,
436+ ImportStateId : subscriptionShort ,
437+ ImportState : true ,
438+ ImportStateVerify : true ,
439+ },
440+ },
441+ })
442+ }
443+
403444func testAccPubsubSubscription_emptyTTL (topic , subscription string ) string {
404445 return fmt .Sprintf (`
405446resource "google_pubsub_topic" "foo" {
@@ -798,3 +839,17 @@ func testAccCheckPubsubSubscriptionCache404(t *testing.T, subName string) resour
798839 return nil
799840 }
800841}
842+
843+ func testAccPubsubSubscription_filter (topic , subscription , filter string ) string {
844+ return fmt .Sprintf (`
845+ resource "google_pubsub_topic" "foo" {
846+ name = "%s"
847+ }
848+
849+ resource "google_pubsub_subscription" "foo" {
850+ name = "%s"
851+ topic = google_pubsub_topic.foo.id
852+ filter = "%s"
853+ }
854+ ` , topic , subscription , filter )
855+ }
0 commit comments