moved test helper
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user