pull all non-request scoped values out of context

This commit is contained in:
Joel Wetzell
2026-05-06 21:33:16 -05:00
parent eb25c73f3a
commit 833bd529d6
98 changed files with 328 additions and 584 deletions

View File

@@ -1,7 +1,6 @@
package processor_test
import (
"context"
"reflect"
"testing"
@@ -35,7 +34,10 @@ func TestRouterInputFromRegistry(t *testing.T) {
payload := "test"
expected := "test"
got, err := processorInstance.Process(test.GetContextWithRouter(t.Context()), common.GetWrappedPayload(t.Context(), payload))
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
Router: test.GetNewTestRouter(),
Payload: payload,
})
if err != nil {
t.Fatalf("router.input processing failed: %s", err)
}
@@ -71,7 +73,7 @@ func TestGoodRouterInput(t *testing.T) {
t.Fatalf("router.input failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(test.GetContextWithRouter(t.Context()), testCase.payload))
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: testCase.payload})
if err != nil {
t.Fatalf("router.input processing failed: %s", err)
}
@@ -85,40 +87,36 @@ func TestGoodRouterInput(t *testing.T) {
func TestBadRouterInput(t *testing.T) {
testCases := []struct {
name string
params map[string]any
payload any
processCtx context.Context
wrappedPayloadCtx context.Context
errorString string
name string
params map[string]any
payload any
router common.RouteIO
errorString string
}{
{
name: "no source param",
params: map[string]any{},
payload: "test",
processCtx: test.GetContextWithRouter(t.Context()),
wrappedPayloadCtx: t.Context(),
errorString: "router.input source error: not found",
name: "no source param",
params: map[string]any{},
payload: "test",
router: test.GetNewTestRouter(),
errorString: "router.input source error: not found",
},
{
name: "non-string source",
params: map[string]any{
"source": 123,
},
payload: "test",
processCtx: test.GetContextWithRouter(t.Context()),
wrappedPayloadCtx: t.Context(),
errorString: "router.input source error: not a string",
payload: "test",
router: test.GetNewTestRouter(),
errorString: "router.input source error: not a string",
},
{
name: "router not found in context",
params: map[string]any{
"source": "test",
},
payload: "test",
processCtx: t.Context(),
wrappedPayloadCtx: t.Context(),
errorString: "router.input no router found",
payload: "test",
router: nil,
errorString: "router.input no router found",
},
}
@@ -142,7 +140,7 @@ func TestBadRouterInput(t *testing.T) {
return
}
got, err := processorInstance.Process(testCase.processCtx, common.GetWrappedPayload(testCase.wrappedPayloadCtx, testCase.payload))
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Router: testCase.router, Payload: testCase.payload})
if err == nil {
t.Fatalf("router.input expected to fail but succeeded, got: %v", got)