google-cloud-go icon indicating copy to clipboard operation
google-cloud-go copied to clipboard

pubsub/pstest: add TopicID field to the Message struct

Open adzil opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe.

Right now there is no way to identify the topic id of a pstest.Message that returned from calling pstest.Server.Messages method.

Describe the solution you'd like

Create a new TopicID field in pstest.Message and ensure that it gets populated when a client is publishing to the fake server.

Describe alternatives you've considered

None, I believe the first solution is pretty straightforward and quite trivial to implement.

Additional context

I can help contribute to this feature request on approval.

adzil avatar Jun 26 '24 10:06 adzil

Could you elaborate a bit more on why this might be helpful for you from a testing perspective?

hongalex avatar Jun 26 '24 20:06 hongalex

Sure! I'm currently writing a package that can automatically route to multiple Pub/Sub topics. In the unit test, I will need to check whether the package routes (or in this case publishes) to the correct topic or not.

Right now, because of there's no topic ID information in the Message, I need to manually create a subscription for each topic. Then, I will need to consume each one of the subscription and join them back again with a topic ID information added. I believe that these type of tests can be greatly simplified if I can just look into the topic information directly on the published messages.

adzil avatar Jun 27 '24 00:06 adzil

Yeah that seems fine to me. If you create a PR for this, I'll be happy to review and help get it merged in.

hongalex avatar Jun 28 '24 22:06 hongalex

@hongalex Thanks! I created the PR at #10510.

adzil avatar Jul 05 '24 06:07 adzil

Thank you for the help! This should be added to the next release.

hongalex avatar Jul 09 '24 01:07 hongalex