mailerlite / mailerlite-go

Go SDK for MailerLite
MIT License
5 stars 4 forks source link

Unable to unit test package usage #23

Open ajpetersons opened 10 months ago

ajpetersons commented 10 months ago

I'd like to be able to unit test my code that I use for Mailerlite access. Ideally I would just take an interface from the package and supply a custom type that satisfies the interface and returns the responses I need for testing. However the issue is that there doesn't exist such an interface and I can't create one myself because there are unexported types returned. Specifically I can mention SubscriberService where operations often return a *rootSubscriber which I can neither add to my own interface nor would be able to return as part of a custom struct.

Please consider a way to help unit test external usages of this package

robgordon89 commented 6 months ago

@ajpetersons open to PR's to fix this 👍

Not sure how it could be done without a breaking change without looking into it in more detail

ajpetersons commented 6 months ago

Would exporting the rootSubscriber and similar types that are returned by operations actually be breaking change for package users? Access to fields would remain the same, access to methods would be possible only if the method is exported. In my code I am unable to declare variable of type *rootSubscriber right now because that's an internal type, so there shouldn't be any issues with that. Maybe I'm missing something, please correct me if so.

The main benefit with this change would be that then I can write my own interface that SubscriberService implements. In main code I would supply struct from this package, but in unit tests I can use any struct I like as long as it satisfies the interface.

robgordon89 commented 6 months ago

i suppose it would not be a breaking change thinking about this, could you maybe create a PR with what you are suggesting I will be happy to accept this if there are no breaking changes for users.