@@ -583,43 +583,64 @@ func TestAccPubsubSubscription_javascriptUdfUpdate(t *testing.T) {
583583 })
584584}
585585
586- func testAccPubsubSubscription_javascriptUdfSettings (topic , subscription , functionName , code string ) string {
587- return fmt .Sprintf (`
588- resource "google_pubsub_topic" "foo" {
589- name = "%s"
590- }
586+ func TestGetComputedTopicName (t * testing.T ) {
587+ type testData struct {
588+ project string
589+ topic string
590+ expected string
591+ }
591592
592- resource "google_pubsub_subscription" "foo" {
593- name = "%s"
594- topic = google_pubsub_topic.foo.id
595- message_transforms {
596- disabled = true
597- javascript_udf {
598- function_name = "%s"
599- code = "%s"
600- }
601- }
602- }
603- ` , topic , subscription , functionName , code )
604- }
593+ var testCases = []testData {
594+ {
595+ project : "my-project" ,
596+ topic : "my-topic" ,
597+ expected : "projects/my-project/topics/my-topic" ,
598+ },
599+ {
600+ project : "my-project" ,
601+ topic : "projects/another-project/topics/my-topic" ,
602+ expected : "projects/another-project/topics/my-topic" ,
603+ },
604+ }
605605
606- func testAccPubsubSubscription_javascriptUdfSettings_noEnabled (topic , subscription , functionName , code string ) string {
607- return fmt .Sprintf (`
608- resource "google_pubsub_topic" "foo" {
609- name = "%s"
606+ for _ , testCase := range testCases {
607+ computedTopicName := pubsub .GetComputedTopicName (testCase .project , testCase .topic )
608+ if computedTopicName != testCase .expected {
609+ t .Fatalf ("bad computed topic name: %s' => expected %s" , computedTopicName , testCase .expected )
610+ }
611+ }
610612}
611613
612- resource "google_pubsub_subscription" "foo" {
613- name = "%s"
614- topic = google_pubsub_topic.foo.id
615- message_transforms {
616- javascript_udf {
617- function_name = "%s"
618- code = "%s"
619- }
620- }
621- }
622- ` , topic , subscription , functionName , code )
614+ func TestAccPubsubSubscription_tags (t * testing.T ) {
615+ t .Parallel ()
616+
617+ subscription := fmt .Sprintf ("tf-test-sub-%s" , acctest .RandString (t , 10 ))
618+ tagKey := acctest .BootstrapSharedTestOrganizationTagKey (t , "pubsub-subscription-tagkey" , nil )
619+ context := map [string ]interface {}{
620+ "topic" : fmt .Sprintf ("tf-test-topic-%s" , acctest .RandString (t , 10 )),
621+ "subscription" : subscription ,
622+ "org" : envvar .GetTestOrgFromEnv (t ),
623+ "tagKey" : tagKey ,
624+ "tagValue" : acctest .BootstrapSharedTestOrganizationTagValue (t , "pubsub-subscription-tagvalue" , tagKey ),
625+ }
626+
627+ acctest .VcrTest (t , resource.TestCase {
628+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
629+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
630+ CheckDestroy : testAccCheckPubsubSubscriptionDestroyProducer (t ),
631+ Steps : []resource.TestStep {
632+ {
633+ Config : testAccPubsubSubscription_tags (context ),
634+ },
635+ {
636+ ResourceName : "google_pubsub_subscription.foo" ,
637+ ImportStateId : subscription ,
638+ ImportState : true ,
639+ ImportStateVerify : true ,
640+ ImportStateVerifyIgnore : []string {"tags" },
641+ },
642+ },
643+ })
623644}
624645
625646func testAccPubsubSubscription_emptyTTL (topic , subscription string ) string {
@@ -1000,34 +1021,6 @@ resource "google_pubsub_subscription" "foo" {
10001021` , topic , subscription )
10011022}
10021023
1003- func TestGetComputedTopicName (t * testing.T ) {
1004- type testData struct {
1005- project string
1006- topic string
1007- expected string
1008- }
1009-
1010- var testCases = []testData {
1011- {
1012- project : "my-project" ,
1013- topic : "my-topic" ,
1014- expected : "projects/my-project/topics/my-topic" ,
1015- },
1016- {
1017- project : "my-project" ,
1018- topic : "projects/another-project/topics/my-topic" ,
1019- expected : "projects/another-project/topics/my-topic" ,
1020- },
1021- }
1022-
1023- for _ , testCase := range testCases {
1024- computedTopicName := pubsub .GetComputedTopicName (testCase .project , testCase .topic )
1025- if computedTopicName != testCase .expected {
1026- t .Fatalf ("bad computed topic name: %s' => expected %s" , computedTopicName , testCase .expected )
1027- }
1028- }
1029- }
1030-
10311024func testAccCheckPubsubSubscriptionCache404 (t * testing.T , subName string ) resource.TestCheckFunc {
10321025 return func (s * terraform.State ) error {
10331026 config := acctest .GoogleProviderConfig (t )
@@ -1061,3 +1054,59 @@ resource "google_pubsub_subscription" "foo" {
10611054}
10621055` , topic , subscription , filter )
10631056}
1057+
1058+ func testAccPubsubSubscription_javascriptUdfSettings (topic , subscription , functionName , code string ) string {
1059+ return fmt .Sprintf (`
1060+ resource "google_pubsub_topic" "foo" {
1061+ name = "%s"
1062+ }
1063+
1064+ resource "google_pubsub_subscription" "foo" {
1065+ name = "%s"
1066+ topic = google_pubsub_topic.foo.id
1067+ message_transforms {
1068+ disabled = true
1069+ javascript_udf {
1070+ function_name = "%s"
1071+ code = "%s"
1072+ }
1073+ }
1074+ }
1075+ ` , topic , subscription , functionName , code )
1076+ }
1077+
1078+ func testAccPubsubSubscription_javascriptUdfSettings_noEnabled (topic , subscription , functionName , code string ) string {
1079+ return fmt .Sprintf (`
1080+ resource "google_pubsub_topic" "foo" {
1081+ name = "%s"
1082+ }
1083+
1084+ resource "google_pubsub_subscription" "foo" {
1085+ name = "%s"
1086+ topic = google_pubsub_topic.foo.id
1087+ message_transforms {
1088+ javascript_udf {
1089+ function_name = "%s"
1090+ code = "%s"
1091+ }
1092+ }
1093+ }
1094+ ` , topic , subscription , functionName , code )
1095+ }
1096+
1097+ func testAccPubsubSubscription_tags (context map [string ]interface {}) string {
1098+ return acctest .Nprintf (`
1099+ resource "google_pubsub_topic" "foo" {
1100+ name = "%{topic}"
1101+ }
1102+
1103+ resource "google_pubsub_subscription" "foo" {
1104+ name = "%{subscription}"
1105+ topic = google_pubsub_topic.foo.id
1106+
1107+ tags = {
1108+ "%{org}/%{tagKey}" = "%{tagValue}"
1109+ }
1110+ }
1111+ ` , context )
1112+ }
0 commit comments