filter_test.go 588 字节
Newer Older
O
obscuren 已提交
1 2
package filter

3 4 5 6
import (
	"testing"
	"time"
)
O
obscuren 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

func TestFilters(t *testing.T) {
	var success bool
	var failure bool

	fm := New()
	fm.Start()
	fm.Install(Generic{
		Str1: "hello",
		Fn: func(data interface{}) {
			success = data.(bool)
		},
	})
	fm.Install(Generic{
		Str1: "hello1",
		Str2: "hello",
		Fn: func(data interface{}) {
			failure = true
		},
	})
	fm.Notify(Generic{Str1: "hello"}, true)
	fm.Stop()

30 31
	time.Sleep(10 * time.Millisecond) // yield to the notifier

O
obscuren 已提交
32 33 34 35 36 37 38 39
	if !success {
		t.Error("expected 'hello' to be posted")
	}

	if failure {
		t.Error("hello1 was triggered")
	}
}