-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcallbacks_test.go
63 lines (46 loc) · 1.23 KB
/
callbacks_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
package callbacks
import (
"context"
"errors"
"github.com/stretchr/testify/assert"
"testing"
)
func TestCallbacks(t *testing.T) {
type EventOne struct{}
type EventTwo struct{}
t.Run("callbacks which are registered are called", func(t *testing.T) {
called := false
funcOne := func(ctx context.Context, event EventOne) error {
called = true
return nil
}
cb := Create()
cb.Add(funcOne)
err := cb.Call(context.Background(), EventOne{})
assert.NoError(t, err)
assert.True(t, called)
})
t.Run("callbacks which are called that error are returned up", func(t *testing.T) {
expectedError := errors.New("callback error")
funcOne := func(ctx context.Context, event EventOne) error {
return expectedError
}
cb := Create()
cb.Add(funcOne)
err := cb.Call(context.Background(), EventOne{})
assert.Error(t, err)
assert.Equal(t, expectedError, err)
})
t.Run("callbacks which are not registered do not call registered callbacks", func(t *testing.T) {
called := false
funcOne := func(ctx context.Context, event EventOne) error {
called = true
return nil
}
cb := Create()
cb.Add(funcOne)
err := cb.Call(context.Background(), EventTwo{})
assert.NoError(t, err)
assert.False(t, called)
})
}