Skip to content
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

Closed
adrianduke opened this issue Sep 29, 2015 · 9 comments
Closed

Make testing easier with interfaces #36

adrianduke opened this issue Sep 29, 2015 · 9 comments
Labels
type: question question directed at the library

Comments

@adrianduke
Copy link

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:

type SGClient interface {
    Send(SGMail) error
}

type SGMail interface {
    AddTo(string) error
    AddTos([]string) error
    AddRecipient(*mail.Address)
    ...
}

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 from Send(m *sendgrid.SGMail) to Send(m sendgrid.SGMailInterface).

@thinkingserious
Copy link
Contributor

If we provided you with a local mock SendGrid server, would that solve your issue?

@adrianduke
Copy link
Author

@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.

@thinkingserious
Copy link
Contributor

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 ;)

@thinkingserious
Copy link
Contributor

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

@thinkingserious thinkingserious added the type: question question directed at the library label May 22, 2016
@hothero
Copy link

hothero commented Jan 4, 2018

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

@thinkingserious
Copy link
Contributor

Hi @hothero,

Could you please voice your feedback here? We are in the process of a refactor and your help would be greatly appreciated!

With Best Regards,

Elmer

@hothero
Copy link

hothero commented Jan 5, 2018

sure, thx @thinkingserious

@AlexMcConnell
Copy link

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. :)

@thinkingserious
Copy link
Contributor

Thanks @AlexMcConnell!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question question directed at the library
Projects
None yet
Development

No branches or pull requests

4 participants