You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying out go-slackbot, and as a TDD user, I want to test my handlers. Right now, I have two choices; either I wrap the https://github.com/BeepBoopHQ/go-slackbot/blob/master/bot.go type in my own, or I create a SomethingHandler than then calls a SomethingHandlerImpl, which abstracts away the slackbot.Bot type.
I think a simpler solution would be to reference to an interface instead of a concrete struct type, and add a New overload that receives the bot. Something like:
func New(slackToken string) *BotInterface {
b := &Bot{Client: slack.New(slackToken)}
return b
}
interface BotInterface interface {
// This is what would be passed around
}
type Bot struct {
// Nothing else changes...
}
I could just make the interface myself, but then I also need to mock MessageHandler (because
TL;DR: I'd like a BotInterface :)
I'm trying out go-slackbot, and as a TDD user, I want to test my handlers. Right now, I have two choices; either I wrap the https://github.com/BeepBoopHQ/go-slackbot/blob/master/bot.go type in my own, or I create a
SomethingHandler
than then calls aSomethingHandlerImpl
, which abstracts away theslackbot.Bot
type.I think a simpler solution would be to reference to an
interface
instead of a concretestruct
type, and add aNew
overload that receives the bot. Something like:I could just make the interface myself, but then I also need to mock
MessageHandler
(becausego-slackbot/types.go
Line 19 in 58027c0
The code might not be perfect, but you get the idea. I can then do:
What do you think?
The text was updated successfully, but these errors were encountered: