From bfe910f4db762ea308aef8180083169041523813 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sat, 19 Jan 2019 09:59:53 -0500 Subject: [PATCH] tests: rm some beers tests, add gok and fix errs --- gok.sh | 23 +++++++++++++++ plugins/beers/beers_test.go | 49 ++++++------------------------- plugins/emojifyme/emojifyme.go | 2 +- plugins/reminder/reminder_test.go | 4 +-- plugins/zork/zork.go | 2 +- 5 files changed, 36 insertions(+), 44 deletions(-) create mode 100755 gok.sh diff --git a/gok.sh b/gok.sh new file mode 100755 index 0000000..50b19d6 --- /dev/null +++ b/gok.sh @@ -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 diff --git a/plugins/beers/beers_test.go b/plugins/beers/beers_test.go index 46840fc..8d14d86 100644 --- a/plugins/beers/beers_test.go +++ b/plugins/beers/beers_test.go @@ -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")) diff --git a/plugins/emojifyme/emojifyme.go b/plugins/emojifyme/emojifyme.go index e6e3e11..424a88b 100644 --- a/plugins/emojifyme/emojifyme.go +++ b/plugins/emojifyme/emojifyme.go @@ -32,7 +32,7 @@ func New(bot bot.Bot) *EmojifyMePlugin { } type Emoji struct { - Aliases []string `json:aliases` + Aliases []string `json:"aliases"` } var emoji []Emoji diff --git a/plugins/reminder/reminder_test.go b/plugins/reminder/reminder_test.go index dc9f38b..afafd5d 100644 --- a/plugins/reminder/reminder_test.go +++ b/plugins/reminder/reminder_test.go @@ -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") diff --git a/plugins/zork/zork.go b/plugins/zork/zork.go index cabc6d2..7e5d0af 100644 --- a/plugins/zork/zork.go +++ b/plugins/zork/zork.go @@ -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