-
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
Create interface for testability #421
Labels
status: help wanted
requesting help from the community
type: community enhancement
feature request not on Twilio's roadmap
Comments
Relates to #420 This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog. |
childish-sambino
added
status: help wanted
requesting help from the community
type: community enhancement
feature request not on Twilio's roadmap
labels
Oct 30, 2020
Hello, package main
import (
"fmt"
"os"
"github.com/sendgrid/sendgrid-go"
"github.com/sendgrid/sendgrid-go/helpers/mail"
"github.com/sendgrid/sendgrid-go/helpers/mock"
)
func main() {
// start mocks server
mock.StartTestServer()
// add mock value
mock.Add(&mock.Mock{
StatusCode: 400,
Body: `{ "errors":[{ "message":"Example error.", "field":"example field" }] }`,
})
simpleSendMail() // Response with mock data
// stop mocks server
mock.StopTestServer()
}
func simpleSendMail() {
from := mail.NewEmail("Example User", "test@example.com")
subject := "Sending with Twilio SendGrid is Fun"
to := mail.NewEmail("Example User", "test@example.com")
plainTextContent := "and easy to do anywhere, even with Go"
htmlContent := "<strong>and easy to do anywhere, even with Go</strong>"
message := mail.NewSingleEmail(from, subject, to, plainTextContent, htmlContent)
// create mock client
client := sendgrid.NewSendClientMock(os.Getenv("SENDGRID_API_KEY"))
response, err := client.Send(message)
if err != nil {
fmt.Println("Simple Sengird Error: ")
fmt.Println(err)
fmt.Println("________________________________")
fmt.Println()
} else {
fmt.Println("Simple Sengird Response: ")
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
fmt.Println("________________________________")
fmt.Println()
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
status: help wanted
requesting help from the community
type: community enhancement
feature request not on Twilio's roadmap
Issue Summary
It would be nice to have an interface available for mocking or a provided fake client that allows clients to utilize the library without sending real emails.
Steps to Reproduce
N/A
Code Snippet
ex:
Then consumers can create their own mocks using https://github.com/vektra/mockery or https://github.com/maxbrunsfeld/counterfeiter
The text was updated successfully, but these errors were encountered: