tests: rm some beers tests, add gok and fix errs

This commit is contained in:
Chris Sexton 2019-01-19 09:59:53 -05:00
parent 91a334b32b
commit bfe910f4db
5 changed files with 36 additions and 44 deletions

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

@ -32,56 +32,25 @@ func makeBeersPlugin(t *testing.T) (*BeersPlugin, *bot.MockBot) {
b := New(mb)
assert.NotNil(t, b)
b.Message(makeMessage("!mkalias beer :beer:"))
b.Message(makeMessage("!mkalias beers :beer:"))
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) {
b, mb := makeBeersPlugin(t)
b.Message(makeMessage("!imbibe"))
assert.Len(t, mb.Messages, 1)
b.Message(makeMessage("!imbibe"))
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.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) {
b, mb := makeBeersPlugin(t)
b.Message(makeMessage("!beers = 3"))
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.Equal(t, 3, it.Count)
}
@ -90,7 +59,7 @@ func TestEqNeg(t *testing.T) {
b, mb := makeBeersPlugin(t)
b.Message(makeMessage("!beers = -3"))
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.Equal(t, 0, it.Count)
}
@ -101,7 +70,7 @@ func TestEqZero(t *testing.T) {
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", "booze")
it, err := counter.GetItem(mb.DB(), "tester", itemName)
assert.Nil(t, err)
assert.Equal(t, 0, it.Count)
}
@ -112,7 +81,7 @@ func TestBeersPlusEq(t *testing.T) {
assert.Len(t, mb.Messages, 1)
b.Message(makeMessage("beers += 5"))
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.Equal(t, 10, it.Count)
}
@ -120,11 +89,11 @@ func TestBeersPlusEq(t *testing.T) {
func TestPuke(t *testing.T) {
b, mb := makeBeersPlugin(t)
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.Equal(t, 5, it.Count)
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.Equal(t, 0, it.Count)
}
@ -132,7 +101,7 @@ func TestPuke(t *testing.T) {
func TestBeersReport(t *testing.T) {
b, mb := makeBeersPlugin(t)
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.Equal(t, 5, it.Count)
b.Message(makeMessage("beers"))

View File

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

View File

@ -178,9 +178,9 @@ func TestBatch(t *testing.T) {
c := New(mb)
c.config.Reminder.MaxBatchAdd = 50
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)
time.Sleep(6 * time.Second)
time.Sleep(2 * time.Second)
assert.Len(t, mb.Messages, 6)
for i := 0; i < 5; i++ {
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
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 {
w.Close()
return err