forked from shammishailaj/go-astiencoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_handler_test.go
More file actions
50 lines (44 loc) · 902 Bytes
/
event_handler_test.go
File metadata and controls
50 lines (44 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package astiencoder
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestEventHandler(t *testing.T) {
// Setup
eh := NewEventHandler()
var es []string
// Callbacks
eh.Add("test-1", "test-1", func(evt Event) bool {
es = append(es, "1")
return true
})
eh.Add("test-2", "test-2", func(evt Event) bool {
es = append(es, "2")
return false
})
eh.AddForTarget("test-1", func(evt Event) bool {
es = append(es, "3")
return false
})
eh.AddForEventName("test-2", func(evt Event) bool {
es = append(es, "4")
return false
})
eh.AddForAll(func(evt Event) bool {
es = append(es, "5")
return false
})
// Emit #1
eh.Emit(Event{
Name: "test-1",
Target: "test-1",
})
require.Equal(t, []string{"1", "3", "5"}, es)
es = []string(nil)
// Emit #2
eh.Emit(Event{
Name: "test-2",
Target: "test-2",
})
require.Equal(t, []string{"2", "4", "5"}, es)
}