So currently I have a http handler that looks like:
type App struct {
}
func (a *App) someHandler(w http.ResponseWriter, r *http.Request) {
var api = slack.New("TOKEN")
users = api.GetUsers()
}
I want to create an interface for this slack.New("...") call so that in my tests the api doesn't make network requests to slack.
How can I mock this New call?
The call New("TOKEN") returns a *Client, see the link below:
func New(token string, options ...Option) *Client {
s := &Client{
token: token,
httpclient: &http.Client{},
log: log.New(os.Stderr, "nlopes/slack", log.LstdFlags|log.Lshortfile),
}
for _, opt := range options {
opt(s)
}
return s
}
https://github.com/nlopes/slack/blob/0f8db5050731c50359e319cf253af5b9997a2b1e/slack.go#L84
I haven't used interfaces that much so not sure if this can't be put in a interface since the call to New is like a constructor?