From 6e3ddbd70ce685ce3e177b00f3600d98a91f26b3 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 17 May 2026 12:00:17 -0400 Subject: [PATCH] moved test helper --- helpers_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ request_test.go | 47 ----------------------------------------------- 2 files changed, 48 insertions(+), 47 deletions(-) diff --git a/helpers_test.go b/helpers_test.go index 768118d..2c112b7 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -4,11 +4,14 @@ import ( "context" "git.wisehodl.dev/jay/go-honeybee" "git.wisehodl.dev/jay/go-mana-component" + "git.wisehodl.dev/jay/go-roots-ws" "github.com/stretchr/testify/assert" "testing" "time" ) +// Async Helpers + const ( TestTimeout = 2 * time.Second TestTick = 10 * time.Millisecond @@ -36,6 +39,8 @@ type mockPool struct { sent chan []byte } +// Mock Pool + func newMockPool(t *testing.T) *mockPool { t.Helper() @@ -85,3 +90,46 @@ func (p *mockPool) receive(data []byte) { ReceivedAt: time.Now(), } } + +// Mock request session harness + +type mockSessionHarness struct { + ctx context.Context + id string + filters [][]byte + req []byte + eose chan struct{} + closed chan struct{} + done chan struct{} + sent chan []byte + send func([]byte) error + terminatedWith chan terminateReason + terminate func(terminateReason) +} + +func newMockSessionHarness() *mockSessionHarness { + ctx := component.MustNew(context.Background(), "prism", "test") + filters := [][]byte{[]byte(`{}`)} + id := "TESTREQ" + sent := make(chan []byte, 2) + send := func(data []byte) error { + sent <- data + return nil + } + terminatedWith := make(chan terminateReason, 1) + terminate := func(r terminateReason) { terminatedWith <- r } + + return &mockSessionHarness{ + ctx: ctx, + id: id, + filters: filters, + req: envelope.EncloseReq(id, filters), + eose: make(chan struct{}), + closed: make(chan struct{}), + done: make(chan struct{}), + sent: sent, + send: send, + terminatedWith: terminatedWith, + terminate: terminate, + } +} diff --git a/request_test.go b/request_test.go index 280076e..f8daa86 100644 --- a/request_test.go +++ b/request_test.go @@ -1,59 +1,12 @@ package prism import ( - "context" "fmt" - "git.wisehodl.dev/jay/go-mana-component" "git.wisehodl.dev/jay/go-roots-ws" "github.com/stretchr/testify/assert" "testing" ) -// Helpers - -type mockSessionHarness struct { - ctx context.Context - id string - filters [][]byte - req []byte - eose chan struct{} - closed chan struct{} - done chan struct{} - sent chan []byte - send func([]byte) error - terminatedWith chan terminateReason - terminate func(terminateReason) -} - -func newMockSessionHarness() *mockSessionHarness { - ctx := component.MustNew(context.Background(), "prism", "test") - filters := [][]byte{[]byte(`{}`)} - id := "TESTREQ" - sent := make(chan []byte, 2) - send := func(data []byte) error { - sent <- data - return nil - } - terminatedWith := make(chan terminateReason, 1) - terminate := func(r terminateReason) { terminatedWith <- r } - - return &mockSessionHarness{ - ctx: ctx, - id: id, - filters: filters, - req: envelope.EncloseReq(id, filters), - eose: make(chan struct{}), - closed: make(chan struct{}), - done: make(chan struct{}), - sent: sent, - send: send, - terminatedWith: terminatedWith, - terminate: terminate, - } -} - -// Tests - // Session tests exercise the session struct in isolation. // The session is constructed directly with mock channels and callbacks. // These tests do not go through RequestManager.