-
Notifications
You must be signed in to change notification settings - Fork 1
/
event_test.go
67 lines (59 loc) · 1.53 KB
/
event_test.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package goofy_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/urionz/goofy"
"github.com/urionz/goofy/event"
)
func TestApplication_Emit(t *testing.T) {
t.Run("test emit", func(t *testing.T) {
app := goofy.New()
err, _ := app.Emit("test", event.M{})
require.NoError(t, err)
})
}
func TestApplication_MustEmit(t *testing.T) {
t.Run("test must emit", func(t *testing.T) {
app := goofy.New()
require.NotPanics(t, func() {
app.MustEmit("test", event.M{})
})
})
}
func TestApplication_AddListener(t *testing.T) {
t.Run("test add listener", func(t *testing.T) {
app := goofy.New()
testValue := "test"
err := app.AddListeners(event.Listeners{
"test": goofy.Listeners(event.ListenerFunc(func(e event.Event) error {
gotTestValue := e.Get("test")
require.NotNil(t, gotTestValue)
require.EqualValues(t, gotTestValue, testValue)
return nil
})),
}).Error()
require.NoError(t, err)
app.Emit("test", event.M{
"test": testValue,
})
})
}
func TestApplication_Dispatch(t *testing.T) {
t.Run("test dispatch event", func(t *testing.T) {
app := goofy.New()
testValue := "test"
err := app.AddListeners(event.Listeners{
"test": goofy.Listeners(event.ListenerFunc(func(e event.Event) error {
gotTestValue := e.Get("test")
require.NotNil(t, gotTestValue)
require.EqualValues(t, gotTestValue, testValue)
return nil
})),
}).Error()
require.NoError(t, err)
err = app.Dispatch("test", event.M{
"test": testValue,
}).Error()
require.NoError(t, err)
})
}