diff --git a/cmd_test.go b/cmd_test.go index 4922239..a0d4c6b 100644 --- a/cmd_test.go +++ b/cmd_test.go @@ -166,10 +166,17 @@ func TestMultiplePeriodicCommands(t *testing.T) { defer b.Close() entries := b.cron.Entries() + + sort.Slice(entries, func(i, j int) bool { + return entries[i].ID < entries[j].ID + }) + + t.Logf("%+v", entries) if len(entries) != 2 { t.Fatal("Should have 2 cron job entries") } if entries[0].Next.Hour() != 8 { + t.Fatal("First cron job should be scheduled for 8am") } if entries[1].Next.Hour() != 12 { @@ -691,20 +698,28 @@ func TestCmdV3WithoutSpecifyingChannel(t *testing.T) { func TestMessageReceiveFilter(t *testing.T) { reset() + + // register a command hello := func(c *Cmd) (string, error) { return "after receive filter: " + c.Message, nil } - RegisterCommand("cmd", "", "", hello) + RegisterCommand("hello", "", "", hello) - modified := func(cd *ChannelData, msg *Message, sender *User, cmd *Cmd) error { + // filter function that modifies the message before command interpretation + var modified filterMessageReceiveFuncV1 + modified = func(cd *ChannelData, msg *Message, sender *User, cmd *Cmd) error { cmd.Message = "modified" return nil } - errored := func(cd *ChannelData, msg *Message, sender *User, cmd *Cmd) error { return errors.New("error") } + + // filter function that errors before command interpretation + var errored filterMessageReceiveFuncV1 + errored = func(cd *ChannelData, msg *Message, sender *User, cmd *Cmd) error { return errors.New("error") } RegisterMessageReceiveFilter("modified", modified) RegisterMessageReceiveFilter("errored", errored) b := newBot() - b.MessageReceived(&ChannelData{Channel: "#go-bot"}, &Message{Text: "!cmd"}, &User{Nick: "user"}) + + b.MessageReceived(&ChannelData{Channel: "#go-bot"}, &Message{Text: "!hello"}, &User{Nick: "user"}) waitMessages(t, 1, 1)