Merge pull request #127 from velour/testcleanup

Testcleanup
This commit is contained in:
Chris Sexton 2019-01-19 10:15:10 -05:00 committed by GitHub
commit 13c6897a0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 178 additions and 171 deletions

View File

@ -1,3 +1,6 @@
language: go language: go
go: 1.x go: 1.x
script: go build env:
- GO111MODULE=on
install: go get -t -v ./... && go build -v ./...
script: ./gok.sh

23
gok.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
o=$(mktemp tmp.XXXXXXXXXX)
fail() {
echo Failed
cat $o | grep -v deprecated
rm $o
exit 1
}
trap fail INT TERM
echo gofmt
gofmt -l $(find . -name '*.go') > $o 2>&1
test $(wc -l $o | awk '{ print $1 }') = "0" || fail
echo govet
go vet ./... > $o 2>&1 || fail
echo go test
go test -test.timeout=60s ./... > $o 2>&1 || fail
rm $o

View File

@ -26,6 +26,7 @@ type BabblerPlugin struct {
Bot bot.Bot Bot bot.Bot
db *sqlx.DB db *sqlx.DB
config *config.Config config *config.Config
WithGoRoutines bool
} }
type Babbler struct { type Babbler struct {
@ -93,6 +94,7 @@ func New(bot bot.Bot) *BabblerPlugin {
Bot: bot, Bot: bot,
db: bot.DB(), db: bot.DB(),
config: bot.Config(), config: bot.Config(),
WithGoRoutines: true,
} }
plugin.createNewWord("") plugin.createNewWord("")

View File

@ -25,12 +25,18 @@ func makeMessage(payload string) msg.Message {
} }
} }
func newBabblerPlugin(mb *bot.MockBot) *BabblerPlugin {
bp := New(mb)
bp.WithGoRoutines = false
return bp
}
func TestBabblerNoBabbler(t *testing.T) { func TestBabblerNoBabbler(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
c.Message(makeMessage("!seabass2 says")) bp.Message(makeMessage("!seabass2 says"))
res := assert.Len(t, mb.Messages, 0) res := assert.Len(t, mb.Messages, 0)
assert.True(t, res) assert.True(t, res)
// assert.Contains(t, mb.Messages[0], "seabass2 babbler not found") // assert.Contains(t, mb.Messages[0], "seabass2 babbler not found")
@ -38,12 +44,12 @@ func TestBabblerNoBabbler(t *testing.T) {
func TestBabblerNothingSaid(t *testing.T) { func TestBabblerNothingSaid(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
res := c.Message(makeMessage("initialize babbler for seabass")) res := bp.Message(makeMessage("initialize babbler for seabass"))
assert.True(t, res) assert.True(t, res)
res = c.Message(makeMessage("!seabass says")) res = bp.Message(makeMessage("!seabass says"))
assert.True(t, res) assert.True(t, res)
assert.Len(t, mb.Messages, 2) assert.Len(t, mb.Messages, 2)
assert.Contains(t, mb.Messages[0], "okay.") assert.Contains(t, mb.Messages[0], "okay.")
@ -52,17 +58,17 @@ func TestBabblerNothingSaid(t *testing.T) {
func TestBabbler(t *testing.T) { func TestBabbler(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("This is a message") seabass := makeMessage("This is a message")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass) res := bp.Message(seabass)
seabass.Body = "This is another message" seabass.Body = "This is another message"
res = c.Message(seabass) res = bp.Message(seabass)
seabass.Body = "This is a long message" seabass.Body = "This is a long message"
res = c.Message(seabass) res = bp.Message(seabass)
res = c.Message(makeMessage("!seabass says")) res = bp.Message(makeMessage("!seabass says"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.True(t, res) assert.True(t, res)
assert.Contains(t, mb.Messages[0], "this is") assert.Contains(t, mb.Messages[0], "this is")
@ -71,17 +77,17 @@ func TestBabbler(t *testing.T) {
func TestBabblerSeed(t *testing.T) { func TestBabblerSeed(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("This is a message") seabass := makeMessage("This is a message")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass) res := bp.Message(seabass)
seabass.Body = "This is another message" seabass.Body = "This is another message"
res = c.Message(seabass) res = bp.Message(seabass)
seabass.Body = "This is a long message" seabass.Body = "This is a long message"
res = c.Message(seabass) res = bp.Message(seabass)
res = c.Message(makeMessage("!seabass says long")) res = bp.Message(makeMessage("!seabass says long"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.True(t, res) assert.True(t, res)
assert.Contains(t, mb.Messages[0], "long message") assert.Contains(t, mb.Messages[0], "long message")
@ -89,17 +95,17 @@ func TestBabblerSeed(t *testing.T) {
func TestBabblerMultiSeed(t *testing.T) { func TestBabblerMultiSeed(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("This is a message") seabass := makeMessage("This is a message")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass) res := bp.Message(seabass)
seabass.Body = "This is another message" seabass.Body = "This is another message"
res = c.Message(seabass) res = bp.Message(seabass)
seabass.Body = "This is a long message" seabass.Body = "This is a long message"
res = c.Message(seabass) res = bp.Message(seabass)
res = c.Message(makeMessage("!seabass says This is a long")) res = bp.Message(makeMessage("!seabass says This is a long"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.True(t, res) assert.True(t, res)
assert.Contains(t, mb.Messages[0], "this is a long message") assert.Contains(t, mb.Messages[0], "this is a long message")
@ -107,17 +113,17 @@ func TestBabblerMultiSeed(t *testing.T) {
func TestBabblerMultiSeed2(t *testing.T) { func TestBabblerMultiSeed2(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("This is a message") seabass := makeMessage("This is a message")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass) res := bp.Message(seabass)
seabass.Body = "This is another message" seabass.Body = "This is another message"
res = c.Message(seabass) res = bp.Message(seabass)
seabass.Body = "This is a long message" seabass.Body = "This is a long message"
res = c.Message(seabass) res = bp.Message(seabass)
res = c.Message(makeMessage("!seabass says is a long")) res = bp.Message(makeMessage("!seabass says is a long"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.True(t, res) assert.True(t, res)
assert.Contains(t, mb.Messages[0], "is a long message") assert.Contains(t, mb.Messages[0], "is a long message")
@ -125,52 +131,52 @@ func TestBabblerMultiSeed2(t *testing.T) {
func TestBabblerBadSeed(t *testing.T) { func TestBabblerBadSeed(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("This is a message") seabass := makeMessage("This is a message")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
c.Message(seabass) bp.Message(seabass)
seabass.Body = "This is another message" seabass.Body = "This is another message"
c.Message(seabass) bp.Message(seabass)
seabass.Body = "This is a long message" seabass.Body = "This is a long message"
c.Message(seabass) bp.Message(seabass)
c.Message(makeMessage("!seabass says noooo this is bad")) bp.Message(makeMessage("!seabass says noooo this is bad"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.Contains(t, mb.Messages[0], "seabass never said 'noooo this is bad'") assert.Contains(t, mb.Messages[0], "seabass never said 'noooo this is bad'")
} }
func TestBabblerBadSeed2(t *testing.T) { func TestBabblerBadSeed2(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("This is a message") seabass := makeMessage("This is a message")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
c.Message(seabass) bp.Message(seabass)
seabass.Body = "This is another message" seabass.Body = "This is another message"
c.Message(seabass) bp.Message(seabass)
seabass.Body = "This is a long message" seabass.Body = "This is a long message"
c.Message(seabass) bp.Message(seabass)
c.Message(makeMessage("!seabass says This is a really")) bp.Message(makeMessage("!seabass says This is a really"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.Contains(t, mb.Messages[0], "seabass never said 'this is a really'") assert.Contains(t, mb.Messages[0], "seabass never said 'this is a really'")
} }
func TestBabblerSuffixSeed(t *testing.T) { func TestBabblerSuffixSeed(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("This is message one") seabass := makeMessage("This is message one")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass) res := bp.Message(seabass)
seabass.Body = "It's easier to test with unique messages" seabass.Body = "It's easier to test with unique messages"
res = c.Message(seabass) res = bp.Message(seabass)
seabass.Body = "hi there" seabass.Body = "hi there"
res = c.Message(seabass) res = bp.Message(seabass)
res = c.Message(makeMessage("!seabass says-tail message one")) res = bp.Message(makeMessage("!seabass says-tail message one"))
res = c.Message(makeMessage("!seabass says-tail with unique")) res = bp.Message(makeMessage("!seabass says-tail with unique"))
assert.Len(t, mb.Messages, 2) assert.Len(t, mb.Messages, 2)
assert.True(t, res) assert.True(t, res)
assert.Contains(t, mb.Messages[0], "this is message one") assert.Contains(t, mb.Messages[0], "this is message one")
@ -179,17 +185,17 @@ func TestBabblerSuffixSeed(t *testing.T) {
func TestBabblerBadSuffixSeed(t *testing.T) { func TestBabblerBadSuffixSeed(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("This is message one") seabass := makeMessage("This is message one")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass) res := bp.Message(seabass)
seabass.Body = "It's easier to test with unique messages" seabass.Body = "It's easier to test with unique messages"
res = c.Message(seabass) res = bp.Message(seabass)
seabass.Body = "hi there" seabass.Body = "hi there"
res = c.Message(seabass) res = bp.Message(seabass)
res = c.Message(makeMessage("!seabass says-tail anything true")) res = bp.Message(makeMessage("!seabass says-tail anything true"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.True(t, res) assert.True(t, res)
assert.Contains(t, mb.Messages[0], "seabass never said 'anything true'") assert.Contains(t, mb.Messages[0], "seabass never said 'anything true'")
@ -197,13 +203,13 @@ func TestBabblerBadSuffixSeed(t *testing.T) {
func TestBabblerBookendSeed(t *testing.T) { func TestBabblerBookendSeed(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("It's easier to test with unique messages") seabass := makeMessage("It's easier to test with unique messages")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass) res := bp.Message(seabass)
res = c.Message(makeMessage("!seabass says-bridge It's easier | unique messages")) res = bp.Message(makeMessage("!seabass says-bridge It's easier | unique messages"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.True(t, res) assert.True(t, res)
assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages") assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages")
@ -211,13 +217,13 @@ func TestBabblerBookendSeed(t *testing.T) {
func TestBabblerBookendSeedShort(t *testing.T) { func TestBabblerBookendSeedShort(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("It's easier to test with unique messages") seabass := makeMessage("It's easier to test with unique messages")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass) res := bp.Message(seabass)
res = c.Message(makeMessage("!seabass says-bridge It's easier to test with | unique messages")) res = bp.Message(makeMessage("!seabass says-bridge It's easier to test with | unique messages"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.True(t, res) assert.True(t, res)
assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages") assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages")
@ -225,13 +231,13 @@ func TestBabblerBookendSeedShort(t *testing.T) {
func TestBabblerBadBookendSeed(t *testing.T) { func TestBabblerBadBookendSeed(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("It's easier to test with unique messages") seabass := makeMessage("It's easier to test with unique messages")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass) res := bp.Message(seabass)
res = c.Message(makeMessage("!seabass says-bridge It's easier | not unique messages")) res = bp.Message(makeMessage("!seabass says-bridge It's easier | not unique messages"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.True(t, res) assert.True(t, res)
assert.Contains(t, mb.Messages[0], "seabass never said 'it's easier ... not unique messages'") assert.Contains(t, mb.Messages[0], "seabass never said 'it's easier ... not unique messages'")
@ -239,13 +245,13 @@ func TestBabblerBadBookendSeed(t *testing.T) {
func TestBabblerMiddleOutSeed(t *testing.T) { func TestBabblerMiddleOutSeed(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("It's easier to test with unique messages") seabass := makeMessage("It's easier to test with unique messages")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass) res := bp.Message(seabass)
res = c.Message(makeMessage("!seabass says-middle-out test with")) res = bp.Message(makeMessage("!seabass says-middle-out test with"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.True(t, res) assert.True(t, res)
assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages") assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages")
@ -253,13 +259,13 @@ func TestBabblerMiddleOutSeed(t *testing.T) {
func TestBabblerBadMiddleOutSeed(t *testing.T) { func TestBabblerBadMiddleOutSeed(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("It's easier to test with unique messages") seabass := makeMessage("It's easier to test with unique messages")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass) res := bp.Message(seabass)
res = c.Message(makeMessage("!seabass says-middle-out anything true")) res = bp.Message(makeMessage("!seabass says-middle-out anything true"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.True(t, res) assert.True(t, res)
assert.Equal(t, mb.Messages[0], "seabass never said 'anything true'") assert.Equal(t, mb.Messages[0], "seabass never said 'anything true'")
@ -267,13 +273,13 @@ func TestBabblerBadMiddleOutSeed(t *testing.T) {
func TestBabblerBatch(t *testing.T) { func TestBabblerBatch(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) 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?") 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 := c.Message(seabass) res := bp.Message(seabass)
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
res = c.Message(makeMessage("!seabass says")) res = bp.Message(makeMessage("!seabass says"))
assert.Len(t, mb.Messages, 2) assert.Len(t, mb.Messages, 2)
assert.True(t, res) assert.True(t, res)
assert.Contains(t, mb.Messages[1], "this is") assert.Contains(t, mb.Messages[1], "this is")
@ -282,27 +288,27 @@ func TestBabblerBatch(t *testing.T) {
func TestBabblerMerge(t *testing.T) { func TestBabblerMerge(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"} bp.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c) assert.NotNil(t, bp)
seabass := makeMessage("<seabass> This is a message") seabass := makeMessage("<seabass> This is a message")
seabass.User = &user.User{Name: "seabass"} seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass) res := bp.Message(seabass)
assert.Len(t, mb.Messages, 0) assert.Len(t, mb.Messages, 0)
seabass.Body = "<seabass> This is another message" seabass.Body = "<seabass> This is another message"
res = c.Message(seabass) res = bp.Message(seabass)
seabass.Body = "<seabass> This is a long message" seabass.Body = "<seabass> This is a long message"
res = c.Message(seabass) res = bp.Message(seabass)
res = c.Message(makeMessage("!merge babbler seabass into seabass2")) res = bp.Message(makeMessage("!merge babbler seabass into seabass2"))
assert.True(t, res) assert.True(t, res)
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
assert.Contains(t, mb.Messages[0], "mooooiggged") assert.Contains(t, mb.Messages[0], "mooooiggged")
res = c.Message(makeMessage("!seabass2 says")) res = bp.Message(makeMessage("!seabass2 says"))
assert.True(t, res) assert.True(t, res)
assert.Len(t, mb.Messages, 2) assert.Len(t, mb.Messages, 2)
@ -312,29 +318,29 @@ func TestBabblerMerge(t *testing.T) {
func TestHelp(t *testing.T) { func TestHelp(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
assert.NotNil(t, c) assert.NotNil(t, bp)
c.Help("channel", []string{}) bp.Help("channel", []string{})
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
} }
func TestBotMessage(t *testing.T) { func TestBotMessage(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
assert.NotNil(t, c) assert.NotNil(t, bp)
assert.False(t, c.BotMessage(makeMessage("test"))) assert.False(t, bp.BotMessage(makeMessage("test")))
} }
func TestEvent(t *testing.T) { func TestEvent(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
assert.NotNil(t, c) assert.NotNil(t, bp)
assert.False(t, c.Event("dummy", makeMessage("test"))) assert.False(t, bp.Event("dummy", makeMessage("test")))
} }
func TestRegisterWeb(t *testing.T) { func TestRegisterWeb(t *testing.T) {
mb := bot.NewMockBot() mb := bot.NewMockBot()
c := New(mb) bp := newBabblerPlugin(mb)
assert.NotNil(t, c) assert.NotNil(t, bp)
assert.Nil(t, c.RegisterWeb()) assert.Nil(t, bp.RegisterWeb())
} }

View File

@ -17,7 +17,11 @@ func (p *BabblerPlugin) initializeBabbler(tokens []string) (string, bool) {
func (p *BabblerPlugin) addToBabbler(babblerName, whatWasSaid string) (string, bool) { func (p *BabblerPlugin) addToBabbler(babblerName, whatWasSaid string) (string, bool) {
babblerId, err := p.getOrCreateBabbler(babblerName) babblerId, err := p.getOrCreateBabbler(babblerName)
if err == nil { if err == nil {
if p.WithGoRoutines {
go p.addToMarkovChain(babblerId, whatWasSaid) go p.addToMarkovChain(babblerId, whatWasSaid)
} else {
p.addToMarkovChain(babblerId, whatWasSaid)
}
} }
return "", false return "", false
} }

View File

@ -32,56 +32,25 @@ func makeBeersPlugin(t *testing.T) (*BeersPlugin, *bot.MockBot) {
b := New(mb) b := New(mb)
assert.NotNil(t, b) assert.NotNil(t, b)
b.Message(makeMessage("!mkalias beer :beer:")) b.Message(makeMessage("!mkalias beer :beer:"))
b.Message(makeMessage("!mkalias beers :beer:"))
return b, mb return b, mb
} }
func TestBeersPlusPlus(t *testing.T) {
b, mb := makeBeersPlugin(t)
b.Message(makeMessage("beers++"))
assert.Len(t, mb.Messages, 1)
b.Message(makeMessage("beers++"))
assert.Len(t, mb.Messages, 2)
it, err := counter.GetItem(mb.DB(), "tester", "booze")
assert.Nil(t, err)
assert.Equal(t, 2, it.Count)
}
func TestBeersMinusMinus(t *testing.T) {
b, mb := makeBeersPlugin(t)
b.Message(makeMessage("beers = 5"))
assert.Len(t, mb.Messages, 1)
b.Message(makeMessage("beers--"))
assert.Len(t, mb.Actions, 1)
it, err := counter.GetItem(mb.DB(), "tester", "booze")
assert.Nil(t, err)
assert.Equal(t, 4, it.Count)
}
func TestImbibe(t *testing.T) { func TestImbibe(t *testing.T) {
b, mb := makeBeersPlugin(t) b, mb := makeBeersPlugin(t)
b.Message(makeMessage("!imbibe")) b.Message(makeMessage("!imbibe"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
b.Message(makeMessage("!imbibe")) b.Message(makeMessage("!imbibe"))
assert.Len(t, mb.Messages, 2) assert.Len(t, mb.Messages, 2)
it, err := counter.GetItem(mb.DB(), "tester", "booze") it, err := counter.GetItem(mb.DB(), "tester", itemName)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, 2, it.Count) assert.Equal(t, 2, it.Count)
} }
func TestBourbon(t *testing.T) {
b, mb := makeBeersPlugin(t)
b.Message(makeMessage("bourbon++"))
assert.Len(t, mb.Messages, 1)
it, err := counter.GetItem(mb.DB(), "tester", "booze")
assert.Nil(t, err)
assert.Equal(t, 2, it.Count)
}
func TestEq(t *testing.T) { func TestEq(t *testing.T) {
b, mb := makeBeersPlugin(t) b, mb := makeBeersPlugin(t)
b.Message(makeMessage("!beers = 3")) b.Message(makeMessage("!beers = 3"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
it, err := counter.GetItem(mb.DB(), "tester", "booze") it, err := counter.GetItem(mb.DB(), "tester", itemName)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, 3, it.Count) assert.Equal(t, 3, it.Count)
} }
@ -90,7 +59,7 @@ func TestEqNeg(t *testing.T) {
b, mb := makeBeersPlugin(t) b, mb := makeBeersPlugin(t)
b.Message(makeMessage("!beers = -3")) b.Message(makeMessage("!beers = -3"))
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
it, err := counter.GetItem(mb.DB(), "tester", "booze") it, err := counter.GetItem(mb.DB(), "tester", itemName)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, 0, it.Count) assert.Equal(t, 0, it.Count)
} }
@ -101,7 +70,7 @@ func TestEqZero(t *testing.T) {
b.Message(makeMessage("!beers = 0")) b.Message(makeMessage("!beers = 0"))
assert.Len(t, mb.Messages, 2) assert.Len(t, mb.Messages, 2)
assert.Contains(t, mb.Messages[1], "reversal of fortune") assert.Contains(t, mb.Messages[1], "reversal of fortune")
it, err := counter.GetItem(mb.DB(), "tester", "booze") it, err := counter.GetItem(mb.DB(), "tester", itemName)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, 0, it.Count) assert.Equal(t, 0, it.Count)
} }
@ -112,7 +81,7 @@ func TestBeersPlusEq(t *testing.T) {
assert.Len(t, mb.Messages, 1) assert.Len(t, mb.Messages, 1)
b.Message(makeMessage("beers += 5")) b.Message(makeMessage("beers += 5"))
assert.Len(t, mb.Messages, 2) assert.Len(t, mb.Messages, 2)
it, err := counter.GetItem(mb.DB(), "tester", "booze") it, err := counter.GetItem(mb.DB(), "tester", itemName)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, 10, it.Count) assert.Equal(t, 10, it.Count)
} }
@ -120,11 +89,11 @@ func TestBeersPlusEq(t *testing.T) {
func TestPuke(t *testing.T) { func TestPuke(t *testing.T) {
b, mb := makeBeersPlugin(t) b, mb := makeBeersPlugin(t)
b.Message(makeMessage("beers += 5")) b.Message(makeMessage("beers += 5"))
it, err := counter.GetItem(mb.DB(), "tester", "booze") it, err := counter.GetItem(mb.DB(), "tester", itemName)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, 5, it.Count) assert.Equal(t, 5, it.Count)
b.Message(makeMessage("puke")) b.Message(makeMessage("puke"))
it, err = counter.GetItem(mb.DB(), "tester", "booze") it, err = counter.GetItem(mb.DB(), "tester", itemName)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, 0, it.Count) assert.Equal(t, 0, it.Count)
} }
@ -132,7 +101,7 @@ func TestPuke(t *testing.T) {
func TestBeersReport(t *testing.T) { func TestBeersReport(t *testing.T) {
b, mb := makeBeersPlugin(t) b, mb := makeBeersPlugin(t)
b.Message(makeMessage("beers += 5")) b.Message(makeMessage("beers += 5"))
it, err := counter.GetItem(mb.DB(), "tester", "booze") it, err := counter.GetItem(mb.DB(), "tester", itemName)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, 5, it.Count) assert.Equal(t, 5, it.Count)
b.Message(makeMessage("beers")) b.Message(makeMessage("beers"))

View File

@ -32,7 +32,7 @@ func New(bot bot.Bot) *EmojifyMePlugin {
} }
type Emoji struct { type Emoji struct {
Aliases []string `json:aliases` Aliases []string `json:"aliases"`
} }
var emoji []Emoji var emoji []Emoji

View File

@ -3,11 +3,11 @@
package nerdepedia package nerdepedia
import ( import (
"bufio"
"fmt" "fmt"
"strings"
"html" "html"
"net/http" "net/http"
"bufio" "strings"
"github.com/velour/catbase/bot" "github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg" "github.com/velour/catbase/bot/msg"

View File

@ -178,9 +178,9 @@ func TestBatch(t *testing.T) {
c := New(mb) c := New(mb)
c.config.Reminder.MaxBatchAdd = 50 c.config.Reminder.MaxBatchAdd = 50
assert.NotNil(t, c) assert.NotNil(t, c)
res := c.Message(makeMessage("!remind testuser every 1s for 5s yikes")) res := c.Message(makeMessage("!remind testuser every 1ms for 5ms yikes"))
assert.True(t, res) assert.True(t, res)
time.Sleep(6 * time.Second) time.Sleep(2 * time.Second)
assert.Len(t, mb.Messages, 6) assert.Len(t, mb.Messages, 6)
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
assert.Contains(t, mb.Messages[i+1], "Hey testuser, tester wanted you to be reminded: yikes") assert.Contains(t, mb.Messages[i+1], "Hey testuser, tester wanted you to be reminded: yikes")

View File

@ -49,7 +49,7 @@ func (p *ZorkPlugin) runZork(ch string) error {
var w io.WriteCloser var w io.WriteCloser
cmd.Stdin, w = io.Pipe() cmd.Stdin, w = io.Pipe()
log.Printf("zork running %s\n", cmd) log.Printf("zork running %v\n", cmd)
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
w.Close() w.Close()
return err return err