-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make testing easier with interfaces #36
Comments
If we provided you with a local mock SendGrid server, would that solve your issue? |
@thinkingserious Thanks for getting back to me! That will definitely help for integration tests, but would still leave a bit of a hole for unit tests (which was my use case). Ideally with unit tests you segregate your unit under test via interfaces and DI, a mock server (if I have understood correctly, I'm thinking stand alone local daemon acting as the SG endpoint giving mock responses) wont be providing segregation but integration. Unless you meant a mock SG object that implemented some kind of interface, in which case that would be perfect. |
Thanks for the additional feedback! I'll need to look deeper, but it might be some time, as I have quite a backlog I'm working through. Pull requests are always welcome ;) |
Hello @adrianduke, This library will be replaced in a few weeks with this one: https://github.com/sendgrid/sendgrid-go/tree/v3beta Please check out how we handle testing in that version. With Best Regards, Elmer |
hello @thinkingserious, thanks for your reply on this thread. Recently I have the same question on it, in v3 it still hard to do testing. any idea on that? or I can make pr to create interface and mock for testing? thx |
sure, thx @thinkingserious |
As I'm sitting here grumbling to myself about having to create a wrapper, I was just coming to create this exact issue. I'll post in the feedback. :) |
Thanks @AlexMcConnell! |
For testing purposes I've not been able to find a way to mock out any of the sendgrid-go library (or smtpapi-go for that matter). Even defining my own local interfaces and mocking those I am defeated by the public API using specific types (Send in particular). It would be great if there were 2 interfaces:
Then the existing SGClient and SGMail should satisfy these interfaces. The AWS Go SDK for example provides an interface for each service and it makes testing very easy. This should be possible without any breaking changes, the only API change would be to
SGClient.Send
going fromSend(m *sendgrid.SGMail)
toSend(m sendgrid.SGMailInterface)
.The text was updated successfully, but these errors were encountered: