mirror of https://github.com/velour/catbase.git
tests: rm some beers tests, add gok and fix errs
This commit is contained in:
parent
91a334b32b
commit
bfe910f4db
|
@ -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
|
|
@ -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"))
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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")
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue