File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,10 @@ func processEvent(
5454 args [1 ] = reflect .ValueOf (event )
5555 returnValues := handlerFn .Call (args )
5656
57- return returnValues [0 ].Interface (), returnValues [1 ].Interface ().(error )
57+ if errVal , ok := returnValues [1 ].Interface ().(error ); ok && errVal != nil {
58+ return nil , errVal
59+ }
60+ return returnValues [0 ].Interface (), nil
5861}
5962
6063func createEvent (rawEvent RawEvent , eventFactories []Factory ) any {
Original file line number Diff line number Diff line change @@ -47,3 +47,36 @@ func TestCreateEventNoFactory(t *testing.T) {
4747 event := createEvent (nil , eventFactories )
4848 assert .Nil (t , event )
4949}
50+
51+ func TestProcessEventWorks (t * testing.T ) {
52+ var handlerCalled = false
53+ handlerMap , err := createHandlerMap (
54+ []any {
55+ func (ctx context.Context , event * events.APIGatewayProxyRequest ) (
56+ * events.APIGatewayProxyResponse ,
57+ error ) {
58+ handlerCalled = true
59+ return & events.APIGatewayProxyResponse {}, nil
60+ }})
61+ assert .NoError (t , err )
62+ assert .NotNil (t , handlerMap )
63+
64+ var factoryCalled = false
65+ cfg := & demuxCfg {
66+ factories : []Factory {
67+ func (ctx * EventContext ) any {
68+ factoryCalled = true
69+ return & events.APIGatewayProxyRequest {}
70+ },
71+ },
72+ handlerMap : handlerMap ,
73+ }
74+
75+ rawEvent := map [string ]any {}
76+
77+ resp , err := processEvent (cfg , context .TODO (), rawEvent )
78+ assert .NoError (t , err )
79+ assert .NotNil (t , resp )
80+ assert .True (t , handlerCalled )
81+ assert .True (t , factoryCalled )
82+ }
You can’t perform that action at this time.
0 commit comments