47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
|
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")
|
||
|
}
|
||
|
}
|