I'm new to go here... my objective is to unit test that a status is being updated in my ready(). I've been looking at https://engineering.aircto.com/writing-testable-code-in-golang/ and trying to figure out how to adapt what they're doing to my use case, filling in gaps of golang knowledge where I can.
I'm getting the error cannot use fakeSession (type *FakeSession) as type *discordgo.Session in argument to ready but I'm not sure why I'm getting this error.
main.go
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
)
var (
// bot token used for this bot when connecting
token = os.Getenv("DISCORD_BOT_TOKEN")
status = os.Getenv("BOT_STATUS")
)
func main() {
// initiate Discord bot
// Register ready as a callback for the ready events.
discordConnection.AddHandler(ready)
// running the app, waiting to receive a close signal
}
// This function will be called (due to AddHandler above) when the bot receives
// the "ready" event from Discord.
func ready(session *discordgo.Session, event *discordgo.Ready) {
// Set the playing status.
session.UpdateStatus(0, status)
}
main_test.go
type FakeSession struct {
status string
idle int
}
func (f *FakeSession) UpdateStatus(idle int, game string) error {
f.idle, f.status = idle, game
return nil
}
func TestStatusIsUpdated(t *testing.T) {
readyDependency := &discordgo.Ready{}
fakeSession := &FakeSession{}
ready(fakeSession, readyDependency)
// @todo assert that idle/game status were set to correct values
}