Skip to content

Commit 48eb480

Browse files
Added tests
1 parent 3b3a704 commit 48eb480

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

demux/event_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,42 @@ func TestProcessEventWorks(t *testing.T) {
8080
assert.True(t, handlerCalled)
8181
assert.True(t, factoryCalled)
8282
}
83+
84+
func TestProcessEventFailsWithUnhandledEventType(t *testing.T) {
85+
handlerMap, err := createHandlerMap(
86+
[]any{})
87+
assert.NoError(t, err)
88+
assert.NotNil(t, handlerMap)
89+
90+
cfg := &demuxCfg{
91+
factories: []Factory{
92+
func(ctx *EventContext) any {
93+
return &events.APIGatewayProxyRequest{}
94+
},
95+
},
96+
handlerMap: handlerMap,
97+
}
98+
99+
rawEvent := map[string]any{}
100+
101+
resp, err := processEvent(cfg, context.TODO(), rawEvent)
102+
assert.EqualError(t, err, "unable to find handler function for event type events.APIGatewayProxyRequest")
103+
assert.Nil(t, resp)
104+
}
105+
106+
func TestProcessEventFailsWithUnknownEventType(t *testing.T) {
107+
handlerMap, err := createHandlerMap([]any{})
108+
assert.NoError(t, err)
109+
assert.NotNil(t, handlerMap)
110+
111+
cfg := &demuxCfg{
112+
factories: []Factory{},
113+
handlerMap: handlerMap,
114+
}
115+
116+
rawEvent := map[string]any{}
117+
118+
resp, err := processEvent(cfg, context.TODO(), rawEvent)
119+
assert.EqualError(t, err, "unable to determine event type for demux")
120+
assert.Nil(t, resp)
121+
}

0 commit comments

Comments
 (0)