From a0f3ee3b050b97e443d4949a04edcf83da64a7fb Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Sun, 22 Mar 2026 22:39:41 -0500 Subject: [PATCH] add tests for wrapped payload --- internal/common/payload_test.go | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 internal/common/payload_test.go diff --git a/internal/common/payload_test.go b/internal/common/payload_test.go new file mode 100644 index 0000000..e2d9ffb --- /dev/null +++ b/internal/common/payload_test.go @@ -0,0 +1,82 @@ +package common_test + +import ( + "context" + "reflect" + "testing" + + "github.com/jwetzell/showbridge-go/internal/common" + "github.com/jwetzell/showbridge-go/internal/test" +) + +func TestGoodGetWrappedPayload(t *testing.T) { + testCases := []struct { + name string + ctx context.Context + payload any + expected common.WrappedPayload + }{ + { + name: "basic", + ctx: t.Context(), + payload: "test", + expected: common.WrappedPayload{ + Payload: "test", + }, + }, + { + name: "with modules in context", + ctx: test.GetContextWithModules(t.Context(), map[string]common.Module{}), + payload: "test", + expected: common.WrappedPayload{ + Payload: "test", + Modules: map[string]common.Module{}, + }, + }, + { + name: "with sender in context", + ctx: test.GetContextWithSender(t.Context(), "sender"), + payload: "test", + expected: common.WrappedPayload{ + Payload: "test", + Sender: "sender", + }, + }, + { + name: "with source in context", + ctx: test.GetContextWithSource(t.Context(), "source"), + payload: "test", + expected: common.WrappedPayload{ + Payload: "test", + Source: "source", + }, + }, + { + name: "with all fields in context", + ctx: test.GetContextWithSource( + test.GetContextWithSender( + test.GetContextWithModules(t.Context(), map[string]common.Module{}), + "sender", + ), + "source", + ), + payload: "test", + expected: common.WrappedPayload{ + Payload: "test", + Modules: map[string]common.Module{}, + Sender: "sender", + Source: "source", + }, + }, + } + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + wrappedPayload := common.GetWrappedPayload(testCase.ctx, testCase.payload) + + if !reflect.DeepEqual(wrappedPayload, testCase.expected) { + t.Fatalf("GetWrappedPayload expected got %+v, expected %+v", wrappedPayload, testCase.expected) + } + }) + } + +}