mirror of https://github.com/velour/catbase.git
tldr: fuck tests
This commit is contained in:
parent
1a066ce979
commit
f8f18acacb
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue