Go Cloud Pubsub Unit-test Demo
A project which demonstrates how we can test GCP services SDK that don't expose interface.
The idea is to define our own interface and wrap the SDK struct so we can generate a mock using gomock.
See the full article here https://medium.com/@albertsundjaja/unit-test-gcp-services-in-go-965bda40d539
Code walkthrough
mock
contains the mock of the interfaces that were generated by gomock
pubsub_client
contains our interface that we defined to wrap the GCP PubSub client
pubsub_service
is our main class that contains the method that we want to unit test. It uses pubsub_client to connect to GCP PubSub
main.go
is the entry point which demonstrates how we can construct the pubsub_client and pubsub_service and glue them together