From 5ee5f33e36d50fc02e1877b7fafe2b8f8e4ec4bc Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Tue, 5 Feb 2019 15:02:15 -0500 Subject: [PATCH] tests: refactor for new system --- bot/mock.go | 2 +- plugins/babbler/babbler_test.go | 156 +++++++++++------------- plugins/beers/beers_test.go | 44 +++---- plugins/couldashouldawoulda/csw_test.go | 16 +-- plugins/counter/counter_test.go | 88 ++++++------- plugins/dice/dice_test.go | 32 ++--- plugins/fact/remember_test.go | 6 +- plugins/leftpad/leftpad_test.go | 34 ++---- plugins/nerdepedia/nerdepeida_test.go | 12 +- plugins/picker/picker_test.go | 8 +- plugins/reminder/reminder_test.go | 93 ++++++-------- plugins/rss/rss_test.go | 8 +- plugins/talker/talker_test.go | 30 ++--- plugins/twitch/twitch_test.go | 6 +- plugins/your/your_test.go | 8 +- 15 files changed, 221 insertions(+), 322 deletions(-) diff --git a/bot/mock.go b/bot/mock.go index 65409fc..70dd1df 100644 --- a/bot/mock.go +++ b/bot/mock.go @@ -47,7 +47,7 @@ func (mb *MockBot) Send(kind Kind, args ...interface{}) (string, error) { return "ERR", fmt.Errorf("Mesasge type unhandled") } func (mb *MockBot) AddPlugin(name string, f Plugin) {} -func (mb *MockBot) Register(name string, kind Kind, cb Callback) {} +func (mb *MockBot) Register(p Plugin, kind Kind, cb Callback) {} func (mb *MockBot) Receive(kind Kind, msg msg.Message, args ...interface{}) {} func (mb *MockBot) Filter(msg msg.Message, s string) string { return s } func (mb *MockBot) LastMessage(ch string) (msg.Message, error) { return msg.Message{}, nil } diff --git a/plugins/babbler/babbler_test.go b/plugins/babbler/babbler_test.go index b07b75f..1631257 100644 --- a/plugins/babbler/babbler_test.go +++ b/plugins/babbler/babbler_test.go @@ -12,12 +12,12 @@ import ( "github.com/velour/catbase/bot/user" ) -func makeMessage(payload string) msg.Message { +func makeMessage(payload string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: "tester"}, Channel: "test", Body: payload, @@ -41,7 +41,7 @@ func TestBabblerNoBabbler(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - bp.Message(makeMessage("!seabass2 says")) + bp.message(makeMessage("!seabass2 says")) res := assert.Len(t, mb.Messages, 0) assert.True(t, res) // assert.Contains(t, mb.Messages[0], "seabass2 babbler not found") @@ -51,9 +51,9 @@ func TestBabblerNothingSaid(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - res := bp.Message(makeMessage("initialize babbler for seabass")) + res := bp.message(makeMessage("initialize babbler for seabass")) assert.True(t, res) - res = bp.Message(makeMessage("!seabass says")) + res = bp.message(makeMessage("!seabass says")) assert.True(t, res) assert.Len(t, mb.Messages, 2) assert.Contains(t, mb.Messages[0], "okay.") @@ -64,14 +64,14 @@ func TestBabbler(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("This is a message") + k, seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} - res := bp.Message(seabass) + res := bp.message(k, seabass) seabass.Body = "This is another message" - res = bp.Message(seabass) + res = bp.message(k, seabass) seabass.Body = "This is a long message" - res = bp.Message(seabass) - res = bp.Message(makeMessage("!seabass says")) + res = bp.message(k, seabass) + res = bp.message(makeMessage("!seabass says")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "this is") @@ -82,14 +82,14 @@ func TestBabblerSeed(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("This is a message") + k, seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} - res := bp.Message(seabass) + res := bp.message(k, seabass) seabass.Body = "This is another message" - res = bp.Message(seabass) + res = bp.message(k, seabass) seabass.Body = "This is a long message" - res = bp.Message(seabass) - res = bp.Message(makeMessage("!seabass says long")) + res = bp.message(k, seabass) + res = bp.message(makeMessage("!seabass says long")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "long message") @@ -99,14 +99,14 @@ func TestBabblerMultiSeed(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("This is a message") + k, seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} - res := bp.Message(seabass) + res := bp.message(k, seabass) seabass.Body = "This is another message" - res = bp.Message(seabass) + res = bp.message(k, seabass) seabass.Body = "This is a long message" - res = bp.Message(seabass) - res = bp.Message(makeMessage("!seabass says This is a long")) + res = bp.message(k, seabass) + res = bp.message(makeMessage("!seabass says This is a long")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "this is a long message") @@ -116,14 +116,14 @@ func TestBabblerMultiSeed2(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("This is a message") + k, seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} - res := bp.Message(seabass) + res := bp.message(k, seabass) seabass.Body = "This is another message" - res = bp.Message(seabass) + res = bp.message(k, seabass) seabass.Body = "This is a long message" - res = bp.Message(seabass) - res = bp.Message(makeMessage("!seabass says is a long")) + res = bp.message(k, seabass) + res = bp.message(makeMessage("!seabass says is a long")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "is a long message") @@ -133,14 +133,14 @@ func TestBabblerBadSeed(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("This is a message") + k, seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} - bp.Message(seabass) + bp.message(k, seabass) seabass.Body = "This is another message" - bp.Message(seabass) + bp.message(k, seabass) seabass.Body = "This is a long message" - bp.Message(seabass) - bp.Message(makeMessage("!seabass says noooo this is bad")) + bp.message(k, seabass) + bp.message(makeMessage("!seabass says noooo this is bad")) assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "seabass never said 'noooo this is bad'") } @@ -149,14 +149,14 @@ func TestBabblerBadSeed2(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("This is a message") + k, seabass := makeMessage("This is a message") seabass.User = &user.User{Name: "seabass"} - bp.Message(seabass) + bp.message(k, seabass) seabass.Body = "This is another message" - bp.Message(seabass) + bp.message(k, seabass) seabass.Body = "This is a long message" - bp.Message(seabass) - bp.Message(makeMessage("!seabass says This is a really")) + bp.message(k, seabass) + bp.message(makeMessage("!seabass says This is a really")) assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "seabass never said 'this is a really'") } @@ -165,15 +165,15 @@ func TestBabblerSuffixSeed(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("This is message one") + k, seabass := makeMessage("This is message one") seabass.User = &user.User{Name: "seabass"} - res := bp.Message(seabass) + res := bp.message(k, seabass) seabass.Body = "It's easier to test with unique messages" - res = bp.Message(seabass) + res = bp.message(k, seabass) seabass.Body = "hi there" - res = bp.Message(seabass) - res = bp.Message(makeMessage("!seabass says-tail message one")) - res = bp.Message(makeMessage("!seabass says-tail with unique")) + res = bp.message(k, seabass) + res = bp.message(makeMessage("!seabass says-tail message one")) + res = bp.message(makeMessage("!seabass says-tail with unique")) assert.Len(t, mb.Messages, 2) assert.True(t, res) assert.Contains(t, mb.Messages[0], "this is message one") @@ -184,14 +184,14 @@ func TestBabblerBadSuffixSeed(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("This is message one") + k, seabass := makeMessage("This is message one") seabass.User = &user.User{Name: "seabass"} - res := bp.Message(seabass) + res := bp.message(k, seabass) seabass.Body = "It's easier to test with unique messages" - res = bp.Message(seabass) + res = bp.message(k, seabass) seabass.Body = "hi there" - res = bp.Message(seabass) - res = bp.Message(makeMessage("!seabass says-tail anything true")) + res = bp.message(k, seabass) + res = bp.message(makeMessage("!seabass says-tail anything true")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "seabass never said 'anything true'") @@ -201,10 +201,10 @@ func TestBabblerBookendSeed(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("It's easier to test with unique messages") + k, seabass := makeMessage("It's easier to test with unique messages") seabass.User = &user.User{Name: "seabass"} - res := bp.Message(seabass) - res = bp.Message(makeMessage("!seabass says-bridge It's easier | unique messages")) + res := bp.message(k, seabass) + res = bp.message(makeMessage("!seabass says-bridge It's easier | unique messages")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages") @@ -214,10 +214,10 @@ func TestBabblerBookendSeedShort(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("It's easier to test with unique messages") + k, seabass := makeMessage("It's easier to test with unique messages") seabass.User = &user.User{Name: "seabass"} - res := bp.Message(seabass) - res = bp.Message(makeMessage("!seabass says-bridge It's easier to test with | unique messages")) + res := bp.message(k, seabass) + res = bp.message(makeMessage("!seabass says-bridge It's easier to test with | unique messages")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages") @@ -227,10 +227,10 @@ func TestBabblerBadBookendSeed(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("It's easier to test with unique messages") + k, seabass := makeMessage("It's easier to test with unique messages") seabass.User = &user.User{Name: "seabass"} - res := bp.Message(seabass) - res = bp.Message(makeMessage("!seabass says-bridge It's easier | not unique messages")) + res := bp.message(k, seabass) + res = bp.message(makeMessage("!seabass says-bridge It's easier | not unique messages")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "seabass never said 'it's easier ... not unique messages'") @@ -240,10 +240,10 @@ func TestBabblerMiddleOutSeed(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("It's easier to test with unique messages") + k, seabass := makeMessage("It's easier to test with unique messages") seabass.User = &user.User{Name: "seabass"} - res := bp.Message(seabass) - res = bp.Message(makeMessage("!seabass says-middle-out test with")) + res := bp.message(k, seabass) + res = bp.message(makeMessage("!seabass says-middle-out test with")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages") @@ -253,10 +253,10 @@ func TestBabblerBadMiddleOutSeed(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("It's easier to test with unique messages") + k, seabass := makeMessage("It's easier to test with unique messages") seabass.User = &user.User{Name: "seabass"} - res := bp.Message(seabass) - res = bp.Message(makeMessage("!seabass says-middle-out anything true")) + res := bp.message(k, seabass) + res = bp.message(makeMessage("!seabass says-middle-out anything true")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Equal(t, mb.Messages[0], "seabass never said 'anything true'") @@ -266,10 +266,10 @@ func TestBabblerBatch(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage("batch learn for seabass This is a message! This is another message. This is not a long message? This is not a message! This is not another message. This is a long message?") - res := bp.Message(seabass) + k, seabass := makeMessage("batch learn for seabass This is a message! This is another message. This is not a long message? This is not a message! This is not another message. This is a long message?") + res := bp.message(k, seabass) assert.Len(t, mb.Messages, 1) - res = bp.Message(makeMessage("!seabass says")) + res = bp.message(makeMessage("!seabass says")) assert.Len(t, mb.Messages, 2) assert.True(t, res) assert.Contains(t, mb.Messages[1], "this is") @@ -281,23 +281,23 @@ func TestBabblerMerge(t *testing.T) { bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - seabass := makeMessage(" This is a message") + k, seabass := makeMessage(" This is a message") seabass.User = &user.User{Name: "seabass"} - res := bp.Message(seabass) + res := bp.message(k, seabass) assert.Len(t, mb.Messages, 0) seabass.Body = " This is another message" - res = bp.Message(seabass) + res = bp.message(k, seabass) seabass.Body = " This is a long message" - res = bp.Message(seabass) + res = bp.message(k, seabass) - res = bp.Message(makeMessage("!merge babbler seabass into seabass2")) + res = bp.message(makeMessage("!merge babbler seabass into seabass2")) assert.True(t, res) assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "mooooiggged") - res = bp.Message(makeMessage("!seabass2 says")) + res = bp.message(makeMessage("!seabass2 says")) assert.True(t, res) assert.Len(t, mb.Messages, 2) @@ -309,24 +309,10 @@ func TestHelp(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) assert.NotNil(t, bp) - bp.Help("channel", []string{}) + bp.help(bot.Help, msg.Message{Channel: "channel"}, []string{}) assert.Len(t, mb.Messages, 1) } -func TestBotMessage(t *testing.T) { - mb := bot.NewMockBot() - bp := newBabblerPlugin(mb) - assert.NotNil(t, bp) - assert.False(t, bp.BotMessage(makeMessage("test"))) -} - -func TestEvent(t *testing.T) { - mb := bot.NewMockBot() - bp := newBabblerPlugin(mb) - assert.NotNil(t, bp) - assert.False(t, bp.Event("dummy", makeMessage("test"))) -} - func TestRegisterWeb(t *testing.T) { mb := bot.NewMockBot() bp := newBabblerPlugin(mb) diff --git a/plugins/beers/beers_test.go b/plugins/beers/beers_test.go index 99964e3..bb34008 100644 --- a/plugins/beers/beers_test.go +++ b/plugins/beers/beers_test.go @@ -13,12 +13,12 @@ import ( "github.com/velour/catbase/plugins/counter" ) -func makeMessage(payload string) msg.Message { +func makeMessage(payload string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: "tester"}, Channel: "test", Body: payload, @@ -31,8 +31,8 @@ func makeBeersPlugin(t *testing.T) (*BeersPlugin, *bot.MockBot) { counter.New(mb) mb.DB().MustExec(`delete from counter; delete from counter_alias;`) b := New(mb) - b.Message(makeMessage("!mkalias beer :beer:")) - b.Message(makeMessage("!mkalias beers :beer:")) + b.message(makeMessage("!mkalias beer :beer:")) + b.message(makeMessage("!mkalias beers :beer:")) return b, mb } @@ -49,9 +49,9 @@ func TestCounter(t *testing.T) { func TestImbibe(t *testing.T) { b, mb := makeBeersPlugin(t) - b.Message(makeMessage("!imbibe")) + b.message(makeMessage("!imbibe")) assert.Len(t, mb.Messages, 1) - b.Message(makeMessage("!imbibe")) + b.message(makeMessage("!imbibe")) assert.Len(t, mb.Messages, 2) it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) @@ -59,7 +59,7 @@ func TestImbibe(t *testing.T) { } func TestEq(t *testing.T) { b, mb := makeBeersPlugin(t) - b.Message(makeMessage("!beers = 3")) + b.message(makeMessage("!beers = 3")) assert.Len(t, mb.Messages, 1) it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) @@ -68,7 +68,7 @@ func TestEq(t *testing.T) { func TestEqNeg(t *testing.T) { b, mb := makeBeersPlugin(t) - b.Message(makeMessage("!beers = -3")) + b.message(makeMessage("!beers = -3")) assert.Len(t, mb.Messages, 1) it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) @@ -77,8 +77,8 @@ func TestEqNeg(t *testing.T) { func TestEqZero(t *testing.T) { b, mb := makeBeersPlugin(t) - b.Message(makeMessage("beers += 5")) - b.Message(makeMessage("!beers = 0")) + b.message(makeMessage("beers += 5")) + b.message(makeMessage("!beers = 0")) assert.Len(t, mb.Messages, 2) assert.Contains(t, mb.Messages[1], "reversal of fortune") it, err := counter.GetItem(mb.DB(), "tester", itemName) @@ -88,9 +88,9 @@ func TestEqZero(t *testing.T) { func TestBeersPlusEq(t *testing.T) { b, mb := makeBeersPlugin(t) - b.Message(makeMessage("beers += 5")) + b.message(makeMessage("beers += 5")) assert.Len(t, mb.Messages, 1) - b.Message(makeMessage("beers += 5")) + b.message(makeMessage("beers += 5")) assert.Len(t, mb.Messages, 2) it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) @@ -99,11 +99,11 @@ func TestBeersPlusEq(t *testing.T) { func TestPuke(t *testing.T) { b, mb := makeBeersPlugin(t) - b.Message(makeMessage("beers += 5")) + b.message(makeMessage("beers += 5")) it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) assert.Equal(t, 5, it.Count) - b.Message(makeMessage("puke")) + b.message(makeMessage("puke")) it, err = counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) assert.Equal(t, 0, it.Count) @@ -111,30 +111,20 @@ func TestPuke(t *testing.T) { func TestBeersReport(t *testing.T) { b, mb := makeBeersPlugin(t) - b.Message(makeMessage("beers += 5")) + b.message(makeMessage("beers += 5")) it, err := counter.GetItem(mb.DB(), "tester", itemName) assert.Nil(t, err) assert.Equal(t, 5, it.Count) - b.Message(makeMessage("beers")) + b.message(makeMessage("beers")) assert.Contains(t, mb.Messages[1], "5 beers") } func TestHelp(t *testing.T) { b, mb := makeBeersPlugin(t) - b.Help("channel", []string{}) + b.help(bot.Help, msg.Message{Channel: "channel"}, []string{}) assert.Len(t, mb.Messages, 1) } -func TestBotMessage(t *testing.T) { - b, _ := makeBeersPlugin(t) - assert.False(t, b.BotMessage(makeMessage("test"))) -} - -func TestEvent(t *testing.T) { - b, _ := makeBeersPlugin(t) - assert.False(t, b.Event("dummy", makeMessage("test"))) -} - func TestRegisterWeb(t *testing.T) { b, _ := makeBeersPlugin(t) assert.Nil(t, b.RegisterWeb()) diff --git a/plugins/couldashouldawoulda/csw_test.go b/plugins/couldashouldawoulda/csw_test.go index 73b5261..de60dc9 100644 --- a/plugins/couldashouldawoulda/csw_test.go +++ b/plugins/couldashouldawoulda/csw_test.go @@ -12,12 +12,12 @@ import ( "github.com/velour/catbase/bot/user" ) -func makeMessage(payload string) msg.Message { +func makeMessage(payload string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: "tester"}, Channel: "test", Body: payload, @@ -29,7 +29,7 @@ func Test0(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!should I drink a beer?")) + res := c.message(makeMessage("!should I drink a beer?")) assert.Len(t, mb.Messages, 1) assert.True(t, res) possibilities := []string{"Yes.", "No.", "Maybe.", "For fucks sake, how should I know?"} @@ -47,7 +47,7 @@ func Test1(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!should I drink a beer or a bourbon?")) + res := c.message(makeMessage("!should I drink a beer or a bourbon?")) assert.Len(t, mb.Messages, 1) assert.True(t, res) possibilities := []string{"The former.", "The latter.", "Obviously the former.", "Clearly the latter.", "Can't it be both?"} @@ -65,7 +65,7 @@ func Test2(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!could I drink a beer or a bourbon?")) + res := c.message(makeMessage("!could I drink a beer or a bourbon?")) assert.Len(t, mb.Messages, 1) assert.True(t, res) possibilities := []string{"Yes.", "No.", "Maybe.", "For fucks sake, how should I know?"} @@ -83,7 +83,7 @@ func Test3(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!would I die if I drank too much bourbon?")) + res := c.message(makeMessage("!would I die if I drank too much bourbon?")) assert.Len(t, mb.Messages, 1) assert.True(t, res) possibilities := []string{"Yes.", "No.", "Maybe.", "For fucks sake, how should I know?"} @@ -101,7 +101,7 @@ func Test4(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!would I die or be sick if I drank all the bourbon?")) + res := c.message(makeMessage("!would I die or be sick if I drank all the bourbon?")) assert.Len(t, mb.Messages, 1) assert.True(t, res) possibilities := []string{"The former.", "The latter.", "Obviously the former.", "Clearly the latter.", "Can't it be both?"} @@ -119,7 +119,7 @@ func Test5(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!should I have another beer or bourbon or tequila?")) + res := c.message(makeMessage("!should I have another beer or bourbon or tequila?")) assert.Len(t, mb.Messages, 1) assert.True(t, res) possibilities := []string{"I'd say option", "You'd be an idiot not to choose the"} diff --git a/plugins/counter/counter_test.go b/plugins/counter/counter_test.go index f1c673c..1cbec0c 100644 --- a/plugins/counter/counter_test.go +++ b/plugins/counter/counter_test.go @@ -22,12 +22,12 @@ func setup(t *testing.T) (*bot.MockBot, *CounterPlugin) { return mb, c } -func makeMessage(payload string) msg.Message { +func makeMessage(payload string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: "tester"}, Channel: "test", Body: payload, @@ -38,8 +38,8 @@ func makeMessage(payload string) msg.Message { func TestThreeSentencesExists(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) - c.Message(makeMessage(":beer:++")) - c.Message(makeMessage(":beer:. Earl Grey. Hot.")) + c.message(makeMessage(":beer:++")) + c.message(makeMessage(":beer:. Earl Grey. Hot.")) item, err := GetItem(mb.DB(), "tester", ":beer:") assert.Nil(t, err) assert.Equal(t, 2, item.Count) @@ -49,7 +49,7 @@ func TestThreeSentencesNotExists(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) item, err := GetItem(mb.DB(), "tester", ":beer:") - c.Message(makeMessage(":beer:. Earl Grey. Hot.")) + c.message(makeMessage(":beer:. Earl Grey. Hot.")) item, err = GetItem(mb.DB(), "tester", ":beer:") assert.Nil(t, err) assert.Equal(t, 0, item.Count) @@ -58,8 +58,8 @@ func TestThreeSentencesNotExists(t *testing.T) { func TestTeaEarlGreyHot(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) - c.Message(makeMessage("Tea. Earl Grey. Hot.")) - c.Message(makeMessage("Tea. Earl Grey. Hot.")) + c.message(makeMessage("Tea. Earl Grey. Hot.")) + c.message(makeMessage("Tea. Earl Grey. Hot.")) item, err := GetItem(mb.DB(), "tester", ":tea:") assert.Nil(t, err) assert.Equal(t, 2, item.Count) @@ -68,8 +68,8 @@ func TestTeaEarlGreyHot(t *testing.T) { func TestTeaTwoPeriods(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) - c.Message(makeMessage("Tea. Earl Grey.")) - c.Message(makeMessage("Tea. Earl Grey.")) + c.message(makeMessage("Tea. Earl Grey.")) + c.message(makeMessage("Tea. Earl Grey.")) item, err := GetItem(mb.DB(), "tester", ":tea:") assert.Nil(t, err) assert.Equal(t, 0, item.Count) @@ -78,8 +78,8 @@ func TestTeaTwoPeriods(t *testing.T) { func TestTeaMultiplePeriods(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) - c.Message(makeMessage("Tea. Earl Grey. Spiked. Hot.")) - c.Message(makeMessage("Tea. Earl Grey. Spiked. Hot.")) + c.message(makeMessage("Tea. Earl Grey. Spiked. Hot.")) + c.message(makeMessage("Tea. Earl Grey. Spiked. Hot.")) item, err := GetItem(mb.DB(), "tester", ":tea:") assert.Nil(t, err) assert.Equal(t, 2, item.Count) @@ -88,9 +88,9 @@ func TestTeaMultiplePeriods(t *testing.T) { func TestTeaGreenHot(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) - c.Message(makeMessage("Tea. Green. Hot.")) - c.Message(makeMessage("Tea. Green. Hot")) - c.Message(makeMessage("Tea. Green. Iced.")) + c.message(makeMessage("Tea. Green. Hot.")) + c.message(makeMessage("Tea. Green. Hot")) + c.message(makeMessage("Tea. Green. Iced.")) item, err := GetItem(mb.DB(), "tester", ":tea:") assert.Nil(t, err) assert.Equal(t, 3, item.Count) @@ -99,8 +99,8 @@ func TestTeaGreenHot(t *testing.T) { func TestTeaUnrelated(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) - c.Message(makeMessage("Tea.")) - c.Message(makeMessage("Tea. It's great.")) + c.message(makeMessage("Tea.")) + c.message(makeMessage("Tea. It's great.")) item, err := GetItem(mb.DB(), "tester", ":tea:") assert.Nil(t, err) assert.Equal(t, 0, item.Count) @@ -109,7 +109,7 @@ func TestTeaUnrelated(t *testing.T) { func TestTeaSkieselQuote(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) - c.Message(makeMessage("blah, this is a whole page of explanation where \"we did local search and used a tabu list\" would have sufficed")) + c.message(makeMessage("blah, this is a whole page of explanation where \"we did local search and used a tabu list\" would have sufficed")) item, err := GetItem(mb.DB(), "tester", ":tea:") assert.Nil(t, err) assert.Equal(t, 0, item.Count) @@ -117,7 +117,7 @@ func TestTeaSkieselQuote(t *testing.T) { func TestTeaUnicodeJapanese(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) - c.Message(makeMessage("Tea. おちや. Hot.")) + c.message(makeMessage("Tea. おちや. Hot.")) item, err := GetItem(mb.DB(), "tester", ":tea:") assert.Nil(t, err) assert.Equal(t, 1, item.Count) @@ -126,8 +126,8 @@ func TestTeaUnicodeJapanese(t *testing.T) { func TestResetMe(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) - c.Message(makeMessage("test++")) - c.Message(makeMessage("!reset me")) + c.message(makeMessage("test++")) + c.message(makeMessage("!reset me")) items, err := GetItems(mb.DB(), "tester") assert.Nil(t, err) assert.Len(t, items, 0) @@ -136,7 +136,7 @@ func TestResetMe(t *testing.T) { func TestCounterOne(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) - c.Message(makeMessage("test++")) + c.message(makeMessage("test++")) assert.Len(t, mb.Messages, 1) assert.Equal(t, mb.Messages[0], "tester has 1 test.") } @@ -144,7 +144,7 @@ func TestCounterOne(t *testing.T) { func TestCounterOneWithSpace(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) - c.Message(makeMessage(":test: ++")) + c.message(makeMessage(":test: ++")) assert.Len(t, mb.Messages, 1) assert.Equal(t, mb.Messages[0], "tester has 1 :test:.") } @@ -153,7 +153,7 @@ func TestCounterFour(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) for i := 0; i < 4; i++ { - c.Message(makeMessage("test++")) + c.message(makeMessage("test++")) } assert.Len(t, mb.Messages, 4) assert.Equal(t, mb.Messages[3], "tester has 4 test.") @@ -163,10 +163,10 @@ func TestCounterDecrement(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) for i := 0; i < 4; i++ { - c.Message(makeMessage("test++")) + c.message(makeMessage("test++")) assert.Equal(t, mb.Messages[i], fmt.Sprintf("tester has %d test.", i+1)) } - c.Message(makeMessage("test--")) + c.message(makeMessage("test--")) assert.Len(t, mb.Messages, 5) assert.Equal(t, mb.Messages[4], "tester has 3 test.") } @@ -175,10 +175,10 @@ func TestFriendCounterDecrement(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) for i := 0; i < 4; i++ { - c.Message(makeMessage("other.test++")) + c.message(makeMessage("other.test++")) assert.Equal(t, mb.Messages[i], fmt.Sprintf("other has %d test.", i+1)) } - c.Message(makeMessage("other.test--")) + c.message(makeMessage("other.test--")) assert.Len(t, mb.Messages, 5) assert.Equal(t, mb.Messages[4], "other has 3 test.") } @@ -187,12 +187,12 @@ func TestDecrementZero(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) for i := 0; i < 4; i++ { - c.Message(makeMessage("test++")) + c.message(makeMessage("test++")) assert.Equal(t, mb.Messages[i], fmt.Sprintf("tester has %d test.", i+1)) } j := 4 for i := 4; i > 0; i-- { - c.Message(makeMessage("test--")) + c.message(makeMessage("test--")) assert.Equal(t, mb.Messages[j], fmt.Sprintf("tester has %d test.", i-1)) j++ } @@ -204,10 +204,10 @@ func TestClear(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) for i := 0; i < 4; i++ { - c.Message(makeMessage("test++")) + c.message(makeMessage("test++")) assert.Equal(t, mb.Messages[i], fmt.Sprintf("tester has %d test.", i+1)) } - res := c.Message(makeMessage("!clear test")) + res := c.message(makeMessage("!clear test")) assert.True(t, res) assert.Len(t, mb.Actions, 1) assert.Equal(t, mb.Actions[0], "chops a few test out of his brain") @@ -217,10 +217,10 @@ func TestCount(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) for i := 0; i < 4; i++ { - c.Message(makeMessage("test++")) + c.message(makeMessage("test++")) assert.Equal(t, mb.Messages[i], fmt.Sprintf("tester has %d test.", i+1)) } - res := c.Message(makeMessage("!count test")) + res := c.message(makeMessage("!count test")) assert.True(t, res) assert.Len(t, mb.Messages, 5) assert.Equal(t, mb.Messages[4], "tester has 4 test.") @@ -230,18 +230,18 @@ func TestInspectMe(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) for i := 0; i < 4; i++ { - c.Message(makeMessage("test++")) + c.message(makeMessage("test++")) assert.Equal(t, mb.Messages[i], fmt.Sprintf("tester has %d test.", i+1)) } for i := 0; i < 2; i++ { - c.Message(makeMessage("fucks++")) + c.message(makeMessage("fucks++")) assert.Equal(t, mb.Messages[i+4], fmt.Sprintf("tester has %d fucks.", i+1)) } for i := 0; i < 20; i++ { - c.Message(makeMessage("cheese++")) + c.message(makeMessage("cheese++")) assert.Equal(t, mb.Messages[i+6], fmt.Sprintf("tester has %d cheese.", i+1)) } - res := c.Message(makeMessage("!inspect me")) + res := c.message(makeMessage("!inspect me")) assert.True(t, res) assert.Len(t, mb.Messages, 27) assert.Equal(t, mb.Messages[26], "tester has the following counters: test: 4, fucks: 2, cheese: 20.") @@ -250,22 +250,10 @@ func TestInspectMe(t *testing.T) { func TestHelp(t *testing.T) { mb, c := setup(t) assert.NotNil(t, c) - c.Help("channel", []string{}) + c.help(bot.Help, msg.Message{Channel: "channel"}, []string{}) assert.Len(t, mb.Messages, 1) } -func TestBotMessage(t *testing.T) { - _, c := setup(t) - assert.NotNil(t, c) - assert.False(t, c.BotMessage(makeMessage("test"))) -} - -func TestEvent(t *testing.T) { - _, c := setup(t) - assert.NotNil(t, c) - assert.False(t, c.Event("dummy", makeMessage("test"))) -} - func TestRegisterWeb(t *testing.T) { _, c := setup(t) assert.NotNil(t, c) diff --git a/plugins/dice/dice_test.go b/plugins/dice/dice_test.go index ec060de..bcb7a26 100644 --- a/plugins/dice/dice_test.go +++ b/plugins/dice/dice_test.go @@ -12,12 +12,12 @@ import ( "github.com/velour/catbase/bot/user" ) -func makeMessage(payload string) msg.Message { +func makeMessage(payload string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: "tester"}, Channel: "test", Body: payload, @@ -29,7 +29,7 @@ func TestDie(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!1d6")) + res := c.message(makeMessage("!1d6")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "tester, you rolled:") @@ -39,7 +39,7 @@ func TestDice(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!5d6")) + res := c.message(makeMessage("!5d6")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "tester, you rolled:") @@ -49,7 +49,7 @@ func TestNotCommand(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("1d6")) + res := c.message(makeMessage("1d6")) assert.False(t, res) assert.Len(t, mb.Messages, 0) } @@ -58,7 +58,7 @@ func TestBadDice(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!aued6")) + res := c.message(makeMessage("!aued6")) assert.False(t, res) assert.Len(t, mb.Messages, 0) } @@ -67,7 +67,7 @@ func TestBadSides(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!1daoeu")) + res := c.message(makeMessage("!1daoeu")) assert.False(t, res) assert.Len(t, mb.Messages, 0) } @@ -76,7 +76,7 @@ func TestLotsOfDice(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!100d100")) + res := c.message(makeMessage("!100d100")) assert.True(t, res) assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "You're a dick.") @@ -86,24 +86,10 @@ func TestHelp(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - c.Help("channel", []string{}) + c.help(bot.Help, msg.Message{Channel: "channel"}, []string{}) assert.Len(t, mb.Messages, 1) } -func TestBotMessage(t *testing.T) { - mb := bot.NewMockBot() - c := New(mb) - assert.NotNil(t, c) - assert.False(t, c.BotMessage(makeMessage("test"))) -} - -func TestEvent(t *testing.T) { - mb := bot.NewMockBot() - c := New(mb) - assert.NotNil(t, c) - assert.False(t, c.Event("dummy", makeMessage("test"))) -} - func TestRegisterWeb(t *testing.T) { mb := bot.NewMockBot() c := New(mb) diff --git a/plugins/fact/remember_test.go b/plugins/fact/remember_test.go index 6e8c8a1..a3ded28 100644 --- a/plugins/fact/remember_test.go +++ b/plugins/fact/remember_test.go @@ -42,7 +42,7 @@ func TestCornerCaseBug(t *testing.T) { p, _, mb := makePlugin(t) for _, m := range msgs { - p.Message(m) + p.message(bot.Message, m) } assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "horse dick") @@ -59,7 +59,7 @@ func TestReact(t *testing.T) { _, p, mb := makePlugin(t) for _, m := range msgs { - p.Message(m) + p.message(bot.Message, m) } assert.Len(t, mb.Reactions, 1) assert.Contains(t, mb.Reactions[0], "jesus") @@ -72,7 +72,7 @@ func TestReactCantLearnSpaces(t *testing.T) { _, p, mb := makePlugin(t) for _, m := range msgs { - p.Message(m) + p.message(bot.Message, m) } assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "not a valid") diff --git a/plugins/leftpad/leftpad_test.go b/plugins/leftpad/leftpad_test.go index 21e4af4..1d97488 100644 --- a/plugins/leftpad/leftpad_test.go +++ b/plugins/leftpad/leftpad_test.go @@ -13,12 +13,12 @@ import ( "github.com/velour/catbase/plugins/counter" ) -func makeMessage(payload string) msg.Message { +func makeMessage(payload string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: "tester"}, Channel: "test", Body: payload, @@ -37,28 +37,28 @@ func makePlugin(t *testing.T) (*LeftpadPlugin, *bot.MockBot) { func TestLeftpad(t *testing.T) { p, mb := makePlugin(t) - p.Message(makeMessage("!leftpad test 8 test")) + p.message(makeMessage("!leftpad test 8 test")) assert.Contains(t, mb.Messages[0], "testtest") assert.Len(t, mb.Messages, 1) } func TestBadNumber(t *testing.T) { p, mb := makePlugin(t) - p.Message(makeMessage("!leftpad test fuck test")) + p.message(makeMessage("!leftpad test fuck test")) assert.Contains(t, mb.Messages[0], "Invalid") assert.Len(t, mb.Messages, 1) } func TestNotCommand(t *testing.T) { p, mb := makePlugin(t) - p.Message(makeMessage("leftpad test fuck test")) + p.message(makeMessage("leftpad test fuck test")) assert.Len(t, mb.Messages, 0) } func TestNoMaxLen(t *testing.T) { p, mb := makePlugin(t) p.config.Set("LeftPad.MaxLen", "0") - p.Message(makeMessage("!leftpad dicks 100 dicks")) + p.message(makeMessage("!leftpad dicks 100 dicks")) assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "dicks") } @@ -67,7 +67,7 @@ func Test50Padding(t *testing.T) { p, mb := makePlugin(t) p.config.Set("LeftPad.MaxLen", "50") assert.Equal(t, 50, p.config.GetInt("LeftPad.MaxLen", 100)) - p.Message(makeMessage("!leftpad dicks 100 dicks")) + p.message(makeMessage("!leftpad dicks 100 dicks")) assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "kill me") } @@ -75,33 +75,17 @@ func Test50Padding(t *testing.T) { func TestUnder50Padding(t *testing.T) { p, mb := makePlugin(t) p.config.Set("LeftPad.MaxLen", "50") - p.Message(makeMessage("!leftpad dicks 49 dicks")) + p.message(makeMessage("!leftpad dicks 49 dicks")) assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "dicks") } func TestNotPadding(t *testing.T) { p, mb := makePlugin(t) - p.Message(makeMessage("!lololol")) + p.message(makeMessage("!lololol")) assert.Len(t, mb.Messages, 0) } -func TestHelp(t *testing.T) { - p, mb := makePlugin(t) - p.Help("channel", []string{}) - assert.Len(t, mb.Messages, 0) -} - -func TestBotMessage(t *testing.T) { - p, _ := makePlugin(t) - assert.False(t, p.BotMessage(makeMessage("test"))) -} - -func TestEvent(t *testing.T) { - p, _ := makePlugin(t) - assert.False(t, p.Event("dummy", makeMessage("test"))) -} - func TestRegisterWeb(t *testing.T) { p, _ := makePlugin(t) assert.Nil(t, p.RegisterWeb()) diff --git a/plugins/nerdepedia/nerdepeida_test.go b/plugins/nerdepedia/nerdepeida_test.go index 5cba343..eb59807 100644 --- a/plugins/nerdepedia/nerdepeida_test.go +++ b/plugins/nerdepedia/nerdepeida_test.go @@ -12,12 +12,12 @@ import ( "github.com/velour/catbase/bot/user" ) -func makeMessage(payload string) msg.Message { +func makeMessage(payload string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: "tester"}, Channel: "test", Body: payload, @@ -29,7 +29,7 @@ func TestWars(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("help me obi-wan")) + res := c.message(makeMessage("help me obi-wan")) assert.Len(t, mb.Messages, 1) assert.True(t, res) } @@ -38,7 +38,7 @@ func TestTrek(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("live long and prosper")) + res := c.message(makeMessage("live long and prosper")) assert.Len(t, mb.Messages, 1) assert.True(t, res) } @@ -47,7 +47,7 @@ func TestDune(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("bless the maker")) + res := c.message(makeMessage("bless the maker")) assert.Len(t, mb.Messages, 1) assert.True(t, res) } @@ -56,7 +56,7 @@ func TestPoke(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("gotta catch em all")) + res := c.message(makeMessage("gotta catch em all")) assert.Len(t, mb.Messages, 1) assert.True(t, res) } diff --git a/plugins/picker/picker_test.go b/plugins/picker/picker_test.go index 0c2dd60..b01684a 100644 --- a/plugins/picker/picker_test.go +++ b/plugins/picker/picker_test.go @@ -12,12 +12,12 @@ import ( "github.com/velour/catbase/bot/user" ) -func makeMessage(payload string) msg.Message { +func makeMessage(payload string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: "tester"}, Channel: "test", Body: payload, @@ -29,7 +29,7 @@ func TestPick2(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!pick 2 { a, b,c}")) + res := c.message(makeMessage("!pick 2 { a, b,c}")) assert.Len(t, mb.Messages, 1) if !res { t.Fatalf("expected a successful choice, got %q", mb.Messages[0]) @@ -40,7 +40,7 @@ func TestPickDefault(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - _ = c.Message(makeMessage("!pick { a}")) + _ = c.message(makeMessage("!pick { a}")) assert.Len(t, mb.Messages, 1) assert.Equal(t, `I've chosen "a" for you.`, mb.Messages[0]) } diff --git a/plugins/reminder/reminder_test.go b/plugins/reminder/reminder_test.go index d3c6155..c4a4e9e 100644 --- a/plugins/reminder/reminder_test.go +++ b/plugins/reminder/reminder_test.go @@ -14,25 +14,16 @@ import ( "github.com/velour/catbase/bot/user" ) -func makeMessage(payload string) msg.Message { - isCmd := strings.HasPrefix(payload, "!") - if isCmd { - payload = payload[1:] - } - return msg.Message{ - User: &user.User{Name: "tester"}, - Channel: "test", - Body: payload, - Command: isCmd, - } +func makeMessage(payload string) (bot.Kind, msg.Message) { + return makeMessageBy(payload, "tester") } -func makeMessageBy(payload, by string) msg.Message { +func makeMessageBy(payload, by string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: by}, Channel: "test", Body: payload, @@ -49,7 +40,7 @@ func setup(t *testing.T) (*ReminderPlugin, *bot.MockBot) { func TestMeReminder(t *testing.T) { c, mb := setup(t) - res := c.Message(makeMessage("!remind me in 1s don't fail this test")) + res := c.message(makeMessage("!remind me in 1s don't fail this test")) time.Sleep(2 * time.Second) assert.Len(t, mb.Messages, 2) assert.True(t, res) @@ -59,7 +50,7 @@ func TestMeReminder(t *testing.T) { func TestReminder(t *testing.T) { c, mb := setup(t) - res := c.Message(makeMessage("!remind testuser in 1s don't fail this test")) + res := c.message(makeMessage("!remind testuser in 1s don't fail this test")) time.Sleep(2 * time.Second) assert.Len(t, mb.Messages, 2) assert.True(t, res) @@ -69,9 +60,9 @@ func TestReminder(t *testing.T) { func TestReminderReorder(t *testing.T) { c, mb := setup(t) - res := c.Message(makeMessage("!remind testuser in 2s don't fail this test 2")) + res := c.message(makeMessage("!remind testuser in 2s don't fail this test 2")) assert.True(t, res) - res = c.Message(makeMessage("!remind testuser in 1s don't fail this test 1")) + res = c.message(makeMessage("!remind testuser in 1s don't fail this test 1")) assert.True(t, res) time.Sleep(5 * time.Second) assert.Len(t, mb.Messages, 4) @@ -83,7 +74,7 @@ func TestReminderReorder(t *testing.T) { func TestReminderParse(t *testing.T) { c, mb := setup(t) - res := c.Message(makeMessage("!remind testuser in unparseable don't fail this test")) + res := c.message(makeMessage("!remind testuser in unparseable don't fail this test")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "Easy cowboy, not sure I can parse that duration.") @@ -91,7 +82,7 @@ func TestReminderParse(t *testing.T) { func TestEmptyList(t *testing.T) { c, mb := setup(t) - res := c.Message(makeMessage("!list reminders")) + res := c.message(makeMessage("!list reminders")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "no pending reminders") @@ -99,11 +90,11 @@ func TestEmptyList(t *testing.T) { func TestList(t *testing.T) { c, mb := setup(t) - res := c.Message(makeMessage("!remind testuser in 5m don't fail this test 1")) + res := c.message(makeMessage("!remind testuser in 5m don't fail this test 1")) assert.True(t, res) - res = c.Message(makeMessage("!remind testuser in 5m don't fail this test 2")) + res = c.message(makeMessage("!remind testuser in 5m don't fail this test 2")) assert.True(t, res) - res = c.Message(makeMessage("!list reminders")) + res = c.message(makeMessage("!list reminders")) assert.True(t, res) assert.Len(t, mb.Messages, 3) assert.Contains(t, mb.Messages[2], "1) tester -> testuser :: don't fail this test 1 @ ") @@ -112,11 +103,11 @@ func TestList(t *testing.T) { func TestListBy(t *testing.T) { c, mb := setup(t) - res := c.Message(makeMessageBy("!remind testuser in 5m don't fail this test 1", "testuser")) + res := c.message(makeMessageBy("!remind testuser in 5m don't fail this test 1", "testuser")) assert.True(t, res) - res = c.Message(makeMessageBy("!remind testuser in 5m don't fail this test 2", "testuser2")) + res = c.message(makeMessageBy("!remind testuser in 5m don't fail this test 2", "testuser2")) assert.True(t, res) - res = c.Message(makeMessage("!list reminders from testuser")) + res = c.message(makeMessage("!list reminders from testuser")) assert.True(t, res) assert.Len(t, mb.Messages, 3) assert.Contains(t, mb.Messages[2], "don't fail this test 1 @ ") @@ -125,11 +116,11 @@ func TestListBy(t *testing.T) { func TestListTo(t *testing.T) { c, mb := setup(t) - res := c.Message(makeMessageBy("!remind testuser2 in 5m don't fail this test 1", "testuser")) + res := c.message(makeMessageBy("!remind testuser2 in 5m don't fail this test 1", "testuser")) assert.True(t, res) - res = c.Message(makeMessageBy("!remind testuser in 5m don't fail this test 2", "testuser2")) + res = c.message(makeMessageBy("!remind testuser in 5m don't fail this test 2", "testuser2")) assert.True(t, res) - res = c.Message(makeMessage("!list reminders to testuser")) + res = c.message(makeMessage("!list reminders to testuser")) assert.True(t, res) assert.Len(t, mb.Messages, 3) assert.NotContains(t, mb.Messages[2], "don't fail this test 1 @ ") @@ -138,11 +129,11 @@ func TestListTo(t *testing.T) { func TestToEmptyList(t *testing.T) { c, mb := setup(t) - res := c.Message(makeMessageBy("!remind testuser2 in 5m don't fail this test 1", "testuser")) + res := c.message(makeMessageBy("!remind testuser2 in 5m don't fail this test 1", "testuser")) assert.True(t, res) - res = c.Message(makeMessageBy("!remind testuser in 5m don't fail this test 2", "testuser2")) + res = c.message(makeMessageBy("!remind testuser in 5m don't fail this test 2", "testuser2")) assert.True(t, res) - res = c.Message(makeMessage("!list reminders to test")) + res = c.message(makeMessage("!list reminders to test")) assert.True(t, res) assert.Len(t, mb.Messages, 3) assert.Contains(t, mb.Messages[2], "no pending reminders") @@ -150,11 +141,11 @@ func TestToEmptyList(t *testing.T) { func TestFromEmptyList(t *testing.T) { c, mb := setup(t) - res := c.Message(makeMessageBy("!remind testuser2 in 5m don't fail this test 1", "testuser")) + res := c.message(makeMessageBy("!remind testuser2 in 5m don't fail this test 1", "testuser")) assert.True(t, res) - res = c.Message(makeMessageBy("!remind testuser in 5m don't fail this test 2", "testuser2")) + res = c.message(makeMessageBy("!remind testuser in 5m don't fail this test 2", "testuser2")) assert.True(t, res) - res = c.Message(makeMessage("!list reminders from test")) + res = c.message(makeMessage("!list reminders from test")) assert.True(t, res) assert.Len(t, mb.Messages, 3) assert.Contains(t, mb.Messages[2], "no pending reminders") @@ -164,9 +155,9 @@ func TestBatchMax(t *testing.T) { c, mb := setup(t) c.config.Set("Reminder.MaxBatchAdd", "10") assert.NotNil(t, c) - res := c.Message(makeMessage("!remind testuser every 1h for 24h yikes")) + res := c.message(makeMessage("!remind testuser every 1h for 24h yikes")) assert.True(t, res) - res = c.Message(makeMessage("!list reminders")) + res = c.message(makeMessage("!list reminders")) assert.True(t, res) time.Sleep(6 * time.Second) assert.Len(t, mb.Messages, 2) @@ -180,11 +171,11 @@ func TestBatchMax(t *testing.T) { func TestCancel(t *testing.T) { c, mb := setup(t) assert.NotNil(t, c) - res := c.Message(makeMessage("!remind testuser in 1m don't fail this test")) + res := c.message(makeMessage("!remind testuser in 1m don't fail this test")) assert.True(t, res) - res = c.Message(makeMessage("!cancel reminder 1")) + res = c.message(makeMessage("!cancel reminder 1")) assert.True(t, res) - res = c.Message(makeMessage("!list reminders")) + res = c.message(makeMessage("!list reminders")) assert.True(t, res) assert.Len(t, mb.Messages, 3) assert.Contains(t, mb.Messages[0], "Sure tester, I'll remind testuser.") @@ -195,7 +186,7 @@ func TestCancel(t *testing.T) { func TestCancelMiss(t *testing.T) { c, mb := setup(t) assert.NotNil(t, c) - res := c.Message(makeMessage("!cancel reminder 1")) + res := c.message(makeMessage("!cancel reminder 1")) assert.True(t, res) assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "failed to find and cancel reminder: 1") @@ -208,13 +199,13 @@ func TestLimitList(t *testing.T) { assert.NotNil(t, c) //Someone can redo this with a single batch add, but I can't locally due to an old version of sqllite (maybe). - res := c.Message(makeMessage("!remind testuser every 1h for 10h don't fail this test")) + res := c.message(makeMessage("!remind testuser every 1h for 10h don't fail this test")) assert.True(t, res) - res = c.Message(makeMessage("!remind testuser every 1h for 10h don't fail this test")) + res = c.message(makeMessage("!remind testuser every 1h for 10h don't fail this test")) assert.True(t, res) - res = c.Message(makeMessage("!remind testuser every 1h for 10h don't fail this test")) + res = c.message(makeMessage("!remind testuser every 1h for 10h don't fail this test")) assert.True(t, res) - res = c.Message(makeMessage("!list reminders")) + res = c.message(makeMessage("!list reminders")) assert.True(t, res) assert.Len(t, mb.Messages, 4) assert.Contains(t, mb.Messages[0], "Sure tester, I'll remind testuser.") @@ -232,22 +223,10 @@ func TestLimitList(t *testing.T) { func TestHelp(t *testing.T) { c, mb := setup(t) assert.NotNil(t, c) - c.Help("channel", []string{}) + c.help(bot.Help, msg.Message{Channel: "channel"}, []string{}) assert.Len(t, mb.Messages, 1) } -func TestBotMessage(t *testing.T) { - c, _ := setup(t) - assert.NotNil(t, c) - assert.False(t, c.BotMessage(makeMessage("test"))) -} - -func TestEvent(t *testing.T) { - c, _ := setup(t) - assert.NotNil(t, c) - assert.False(t, c.Event("dummy", makeMessage("test"))) -} - func TestRegisterWeb(t *testing.T) { c, _ := setup(t) assert.NotNil(t, c) diff --git a/plugins/rss/rss_test.go b/plugins/rss/rss_test.go index 7c20fd1..900031a 100644 --- a/plugins/rss/rss_test.go +++ b/plugins/rss/rss_test.go @@ -11,12 +11,12 @@ import ( "github.com/velour/catbase/bot/user" ) -func makeMessage(payload string) msg.Message { +func makeMessage(payload string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: "tester"}, Channel: "test", Body: payload, @@ -28,7 +28,7 @@ func TestRSS(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!rss http://rss.cnn.com/rss/edition.rss")) + res := c.message(makeMessage("!rss http://rss.cnn.com/rss/edition.rss")) assert.Len(t, mb.Messages, 1) assert.True(t, res) } @@ -38,7 +38,7 @@ func TestRSSPaging(t *testing.T) { c := New(mb) assert.NotNil(t, c) for i := 0; i < 20; i++ { - res := c.Message(makeMessage("!rss http://rss.cnn.com/rss/edition.rss")) + res := c.message(makeMessage("!rss http://rss.cnn.com/rss/edition.rss")) assert.True(t, res) } diff --git a/plugins/talker/talker_test.go b/plugins/talker/talker_test.go index dd45ec1..2408f45 100644 --- a/plugins/talker/talker_test.go +++ b/plugins/talker/talker_test.go @@ -12,12 +12,12 @@ import ( "github.com/velour/catbase/bot/user" ) -func makeMessage(payload string) msg.Message { +func makeMessage(payload string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: "tester"}, Channel: "test", Body: payload, @@ -29,7 +29,7 @@ func TestGoatse(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("goatse")) + res := c.message(makeMessage("goatse")) assert.Len(t, mb.Messages, 0) assert.False(t, res) } @@ -38,7 +38,7 @@ func TestGoatseCommand(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!goatse")) + res := c.message(makeMessage("!goatse")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "g o a t s e") @@ -48,7 +48,7 @@ func TestGoatseWithNickCommand(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!goatse seabass")) + res := c.message(makeMessage("!goatse seabass")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "g o a t s e") @@ -59,7 +59,7 @@ func TestSay(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("say hello")) + res := c.message(makeMessage("say hello")) assert.Len(t, mb.Messages, 0) assert.False(t, res) } @@ -68,7 +68,7 @@ func TestSayCommand(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - res := c.Message(makeMessage("!say hello")) + res := c.message(makeMessage("!say hello")) assert.Len(t, mb.Messages, 1) assert.True(t, res) assert.Contains(t, mb.Messages[0], "hello") @@ -78,24 +78,10 @@ func TestHelp(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) - c.Help("channel", []string{}) + c.help(bot.Help, msg.Message{Channel: "channel"}, []string{}) assert.Len(t, mb.Messages, 1) } -func TestBotMessage(t *testing.T) { - mb := bot.NewMockBot() - c := New(mb) - assert.NotNil(t, c) - assert.False(t, c.BotMessage(makeMessage("test"))) -} - -func TestEvent(t *testing.T) { - mb := bot.NewMockBot() - c := New(mb) - assert.NotNil(t, c) - assert.False(t, c.Event("dummy", makeMessage("test"))) -} - func TestRegisterWeb(t *testing.T) { mb := bot.NewMockBot() c := New(mb) diff --git a/plugins/twitch/twitch_test.go b/plugins/twitch/twitch_test.go index 728fe00..b3d88ec 100644 --- a/plugins/twitch/twitch_test.go +++ b/plugins/twitch/twitch_test.go @@ -12,12 +12,12 @@ import ( "github.com/velour/catbase/bot/user" ) -func makeMessage(payload string) msg.Message { +func makeMessage(payload string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: "tester"}, Channel: "test", Body: payload, @@ -44,6 +44,6 @@ func makeTwitchPlugin(t *testing.T) (*TwitchPlugin, *bot.MockBot) { func TestTwitch(t *testing.T) { b, mb := makeTwitchPlugin(t) - b.Message(makeMessage("!twitch status")) + b.message(makeMessage("!twitch status")) assert.NotEmpty(t, mb.Messages) } diff --git a/plugins/your/your_test.go b/plugins/your/your_test.go index 75a0ace..3c6136a 100644 --- a/plugins/your/your_test.go +++ b/plugins/your/your_test.go @@ -12,12 +12,12 @@ import ( "github.com/velour/catbase/bot/user" ) -func makeMessage(payload string) msg.Message { +func makeMessage(payload string) (bot.Kind, msg.Message) { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return msg.Message{ + return bot.Message, msg.Message{ User: &user.User{Name: "tester"}, Channel: "test", Body: payload, @@ -39,7 +39,7 @@ func TestReplacement(t *testing.T) { c.config.Set("your.replacements.0.freq", "1.0") c.config.Set("your.replacements.0.this", "fuck") c.config.Set("your.replacements.0.that", "duck") - res := c.Message(makeMessage("fuck a duck")) + res := c.message(makeMessage("fuck a duck")) assert.True(t, res) assert.Len(t, mb.Messages, 1) assert.Contains(t, mb.Messages[0], "duck a duck") @@ -60,6 +60,6 @@ func TestNoReplacement(t *testing.T) { c.config.Set("your.replacements.2.freq", "1.0") c.config.Set("your.replacements.2.this", "Fuck") c.config.Set("your.replacements.2.that", "duck") - c.Message(makeMessage("fuck a duck")) + c.message(makeMessage("fuck a duck")) assert.Len(t, mb.Messages, 0) }