Initial commit: hugot lysenko
This commit is contained in:
46
handlers/ignore/ignore_test.go
Normal file
46
handlers/ignore/ignore_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package ignore_test
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/tcolgate/hugot"
|
||||
"golang.org/x/net/context"
|
||||
"ur.gs/lysenko/handlers/ignore"
|
||||
)
|
||||
|
||||
type DummyHearsHandler struct {
|
||||
Called bool
|
||||
}
|
||||
|
||||
func (h *DummyHearsHandler) Describe() (string, string) {
|
||||
return "", ""
|
||||
}
|
||||
|
||||
func (h *DummyHearsHandler) Hears() *regexp.Regexp {
|
||||
return regexp.MustCompile(``)
|
||||
}
|
||||
|
||||
func (h *DummyHearsHandler) Heard(ctx context.Context, w hugot.ResponseWriter, m *hugot.Message, submatches [][]string) {
|
||||
h.Called = true
|
||||
}
|
||||
|
||||
func TestIgnoreHearsPassesOKNick(t *testing.T) {
|
||||
msg := hugot.Message{}
|
||||
dummy := &DummyHearsHandler{}
|
||||
ignorer := ignore.NewHears([]string{"foo"}, dummy)
|
||||
ignorer.Heard(context.TODO(), hugot.NewNullResponseWriter(msg), &msg, [][]string{})
|
||||
if !dummy.Called {
|
||||
t.Fatal("Dummy not called when it should have been")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIgnoreHearsBlocksBadNick(t *testing.T) {
|
||||
msg := hugot.Message{From: "foo"}
|
||||
dummy := &DummyHearsHandler{}
|
||||
ignorer := ignore.NewHears([]string{"foo"}, dummy)
|
||||
ignorer.Heard(context.TODO(), hugot.NewNullResponseWriter(msg), &msg, [][]string{})
|
||||
if dummy.Called {
|
||||
t.Fatal("Dummy called when it shouldn't have been")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user