Fixed incorrect assignable types order in invocation

This commit is contained in:
Leon Mika 2024-03-10 00:09:33 +00:00
parent e7cb026708
commit dbce4f6dce
2 changed files with 19 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package events
import (
"context"
"errors"
"fmt"
"testing"
@ -34,6 +35,23 @@ func TestNew_Lifecycle(t *testing.T) {
}, receives)
}
func TestFire(t *testing.T) {
t.Run("should preserve context.Context", func(t *testing.T) {
var wasFired bool
d := New()
d.On("event", func(ctx context.Context) {
assert.NotNil(t, ctx)
wasFired = true
})
d.Fire("event", context.Background())
assert.True(t, wasFired)
})
}
func TestTryFire(t *testing.T) {
errVal := errors.New("bang")

View File

@ -27,7 +27,7 @@ func (rh *receiptHandler) invoke(values preparedArgs) error {
for i := range args {
args[i] = reflect.Zero(rh.funcType.In(i))
if i < len(values) {
if rh.funcType.In(i).AssignableTo(values[i].Type()) {
if values[i].Type().AssignableTo(rh.funcType.In(i)) {
args[i] = values[i]
}
}