mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-08-18 04:33:56 +00:00
switch modules to accept an InputHandler instead of the full router
This commit is contained in:
@@ -20,12 +20,12 @@ type RouterInput struct {
|
||||
func (ro *RouterInput) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||
|
||||
payload := wrappedPayload.Payload
|
||||
if wrappedPayload.Router == nil {
|
||||
if wrappedPayload.InputHandler == nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, errors.New("router.input no router found")
|
||||
return wrappedPayload, errors.New("router.input no input handler found")
|
||||
}
|
||||
|
||||
_, err := wrappedPayload.Router.HandleInput(ctx, ro.SourceId, payload)
|
||||
_, err := wrappedPayload.InputHandler(ctx, ro.SourceId, payload)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
|
||||
@@ -113,7 +113,7 @@ func TestBadKvSet(t *testing.T) {
|
||||
name: "no module param",
|
||||
payload: test.TestStruct{Data: "hello"},
|
||||
params: map[string]any{
|
||||
"key": "test",
|
||||
"key": "test",
|
||||
},
|
||||
wrappedPayloadModules: map[string]common.Module{
|
||||
"test": &test.TestKVModule{},
|
||||
|
||||
@@ -34,8 +34,10 @@ func TestModuleOutputFromRegistry(t *testing.T) {
|
||||
payload := "test"
|
||||
expected := "test"
|
||||
|
||||
router := test.GetNewTestRouter()
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
|
||||
Router: test.GetNewTestRouter(),
|
||||
InputHandler: router.HandleInput,
|
||||
Modules: map[string]common.Module{"test": &test.TestOutputModule{}},
|
||||
Payload: payload,
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestRouterInputFromRegistry(t *testing.T) {
|
||||
expected := "test"
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
|
||||
Router: test.GetNewTestRouter(),
|
||||
InputHandler: test.GetNewTestRouter().HandleInput,
|
||||
Payload: payload,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -86,18 +86,19 @@ func TestGoodRouterInput(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBadRouterInput(t *testing.T) {
|
||||
router := test.GetNewTestRouter()
|
||||
testCases := []struct {
|
||||
name string
|
||||
params map[string]any
|
||||
payload any
|
||||
router common.RouteIO
|
||||
errorString string
|
||||
name string
|
||||
params map[string]any
|
||||
payload any
|
||||
inputHandler common.InputHandler
|
||||
errorString string
|
||||
}{
|
||||
{
|
||||
name: "no source param",
|
||||
params: map[string]any{},
|
||||
payload: "test",
|
||||
router: test.GetNewTestRouter(),
|
||||
inputHandler: router.HandleInput,
|
||||
errorString: "router.input source error: not found",
|
||||
},
|
||||
{
|
||||
@@ -106,7 +107,7 @@ func TestBadRouterInput(t *testing.T) {
|
||||
"source": 123,
|
||||
},
|
||||
payload: "test",
|
||||
router: test.GetNewTestRouter(),
|
||||
inputHandler: router.HandleInput,
|
||||
errorString: "router.input source error: not a string",
|
||||
},
|
||||
{
|
||||
@@ -115,8 +116,8 @@ func TestBadRouterInput(t *testing.T) {
|
||||
"source": "test",
|
||||
},
|
||||
payload: "test",
|
||||
router: nil,
|
||||
errorString: "router.input no router found",
|
||||
inputHandler: nil,
|
||||
errorString: "router.input no input handler found",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -140,7 +141,7 @@ func TestBadRouterInput(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Router: testCase.router, Payload: testCase.payload})
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{InputHandler: testCase.inputHandler, Payload: testCase.payload})
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("router.input expected to fail but succeeded, got: %v", got)
|
||||
|
||||
Reference in New Issue
Block a user