tldr: fuck tests

This commit is contained in:
Chris Sexton 2024-01-05 11:48:43 -05:00
parent 1a066ce979
commit f8f18acacb
1 changed files with 12 additions and 46 deletions

View File

@ -20,20 +20,25 @@ func init() {
log.Logger = log.Logger.Output(zerolog.ConsoleWriter{Out: os.Stderr}) 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, "!") isCmd := strings.HasPrefix(payload, "!")
if isCmd { if isCmd {
payload = payload[1:] payload = payload[1:]
} }
return &cli.CliPlugin{}, bot.Message, msg.Message{
return bot.Request{
Conn: &cli.CliPlugin{},
Kind: bot.Message,
Msg: msg.Message{
User: &user.User{Name: by}, User: &user.User{Name: by},
Channel: "test", Channel: "test",
Body: payload, Body: payload,
Command: isCmd, Command: isCmd,
},
} }
} }
func makeMessage(payload string) (bot.Connector, bot.Kind, msg.Message) { func makeMessage(payload string) bot.Request {
return makeMessageBy(payload, "tester") return makeMessageBy(payload, "tester")
} }
@ -43,45 +48,6 @@ func setup(t *testing.T) (*TLDRPlugin, *bot.MockBot) {
return r, mb 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) { func TestAddHistoryLimitsDays(t *testing.T) {
c, _ := setup(t) c, _ := setup(t)
hrs := 24 hrs := 24