mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-05-07 10:05:54 +00:00
pull all non-request scoped values out of context
This commit is contained in:
@@ -43,10 +43,9 @@ func (r *Route) Input() string {
|
||||
return r.input
|
||||
}
|
||||
|
||||
func (r *Route) ProcessPayload(ctx context.Context, payload any) (any, error) {
|
||||
wrappedPayload := common.GetWrappedPayload(ctx, payload)
|
||||
func (r *Route) ProcessPayload(ctx context.Context, wrappedPayload common.WrappedPayload) (any, error) {
|
||||
tracer := otel.Tracer("route")
|
||||
processCtx, processSpan := tracer.Start(ctx, "ProcessPayload", trace.WithAttributes(attribute.String("payload.type", fmt.Sprintf("%T", payload))))
|
||||
processCtx, processSpan := tracer.Start(ctx, "ProcessPayload", trace.WithAttributes(attribute.String("payload.type", fmt.Sprintf("%T", wrappedPayload.Payload))))
|
||||
defer processSpan.End()
|
||||
for processorIndex, processor := range r.processors {
|
||||
processorCtx, processorSpan := otel.Tracer("processor").Start(processCtx, "process", trace.WithAttributes(attribute.Int("processor.index", processorIndex), attribute.String("processor.type", processor.Type())))
|
||||
|
||||
@@ -55,7 +55,10 @@ func TestGoodRouteHandleInput(t *testing.T) {
|
||||
}
|
||||
|
||||
inputData := "test input data"
|
||||
payload, err := testRoute.ProcessPayload(context.WithValue(t.Context(), common.RouterContextKey, &MockRouter{}), inputData)
|
||||
payload, err := testRoute.ProcessPayload(t.Context(), common.WrappedPayload{
|
||||
Router: &MockRouter{},
|
||||
Payload: inputData,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("route ProcessPayload returned error: %v", err)
|
||||
}
|
||||
@@ -90,7 +93,10 @@ func TestRouteHandleInputWithProcessorError(t *testing.T) {
|
||||
}
|
||||
|
||||
inputData := "test input data"
|
||||
_, err = testRoute.ProcessPayload(context.WithValue(t.Context(), common.RouterContextKey, &MockRouter{}), inputData)
|
||||
_, err = testRoute.ProcessPayload(t.Context(), common.WrappedPayload{
|
||||
Router: &MockRouter{},
|
||||
Payload: inputData,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatalf("route HandleOutput did not return error for bad processor")
|
||||
}
|
||||
@@ -115,7 +121,10 @@ func TestRouteHandleNilPayload(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
payload, err := testRoute.ProcessPayload(context.WithValue(t.Context(), common.RouterContextKey, &MockRouter{}), nil)
|
||||
payload, err := testRoute.ProcessPayload(t.Context(), common.WrappedPayload{
|
||||
Router: &MockRouter{},
|
||||
Payload: nil,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("route ProcessPayload returned error: %v", err)
|
||||
}
|
||||
@@ -143,7 +152,10 @@ func TestRouteHandleNilPayloadFromProcessor(t *testing.T) {
|
||||
t.Fatalf("route failed to create: %v", err)
|
||||
}
|
||||
|
||||
_, err = testRoute.ProcessPayload(context.WithValue(t.Context(), common.RouterContextKey, &MockRouter{}), "test")
|
||||
_, err = testRoute.ProcessPayload(t.Context(), common.WrappedPayload{
|
||||
Router: &MockRouter{},
|
||||
Payload: "test",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("route HandleOutput returned error for nil payload: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user