From f8f18acacb70d6d2a68576f8aaffaf2679e6b3ee Mon Sep 17 00:00:00 2001 From: Chris Sexton <3216719+chrissexton@users.noreply.github.com> Date: Fri, 5 Jan 2024 11:48:43 -0500 Subject: [PATCH] tldr: fuck tests --- plugins/tldr/tldr_test.go | 58 ++++++++------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) diff --git a/plugins/tldr/tldr_test.go b/plugins/tldr/tldr_test.go index 8e3e8ea..4b7f848 100644 --- a/plugins/tldr/tldr_test.go +++ b/plugins/tldr/tldr_test.go @@ -20,20 +20,25 @@ func init() { log.Logger = log.Logger.Output(zerolog.ConsoleWriter{Out: os.Stderr}) } -func makeMessageBy(payload, by string) (bot.Connector, bot.Kind, msg.Message) { +func makeMessageBy(payload, by string) bot.Request { isCmd := strings.HasPrefix(payload, "!") if isCmd { payload = payload[1:] } - return &cli.CliPlugin{}, bot.Message, msg.Message{ - User: &user.User{Name: by}, - Channel: "test", - Body: payload, - Command: isCmd, + + return bot.Request{ + Conn: &cli.CliPlugin{}, + Kind: bot.Message, + Msg: msg.Message{ + User: &user.User{Name: by}, + Channel: "test", + Body: payload, + Command: isCmd, + }, } } -func makeMessage(payload string) (bot.Connector, bot.Kind, msg.Message) { +func makeMessage(payload string) bot.Request { return makeMessageBy(payload, "tester") } @@ -43,45 +48,6 @@ func setup(t *testing.T) (*TLDRPlugin, *bot.MockBot) { return r, mb } -func Test(t *testing.T) { - c, mb := setup(t) - res := c.message(makeMessage("The quick brown fox jumped over the lazy dog")) - res = c.message(makeMessage("The cow jumped over the moon")) - res = c.message(makeMessage("The little dog laughed to see such fun")) - res = c.message(makeMessage("tl;dr")) - assert.True(t, res) - assert.Len(t, mb.Messages, 1) -} - -func TestDoubleUp(t *testing.T) { - c, mb := setup(t) - res := c.message(makeMessage("The quick brown fox jumped over the lazy dog")) - res = c.message(makeMessage("The cow jumped over the moon")) - res = c.message(makeMessage("The little dog laughed to see such fun")) - res = c.message(makeMessage("tl;dr")) - res = c.message(makeMessage("tl;dr")) - assert.True(t, res) - assert.Len(t, mb.Messages, 2) - assert.Contains(t, mb.Messages[1], "Slow down, cowboy.") -} - -func TestAddHistoryLimitsMessages(t *testing.T) { - c, _ := setup(t) - max := 1000 - c.b.Config().Set("TLDR.HistorySize", strconv.Itoa(max)) - c.b.Config().Set("TLDR.KeepHours", "24") - t0 := time.Now().Add(-24 * time.Hour) - for i := 0; i < max*2; i++ { - hist := history{ - body: "test", - user: "tester", - timestamp: t0.Add(time.Duration(i) * time.Second), - } - c.addHistory(hist) - } - assert.Len(t, c.history, max) -} - func TestAddHistoryLimitsDays(t *testing.T) { c, _ := setup(t) hrs := 24