You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB
Go

package testutil
import (
"context"
"github.com/noahlann/nnet/internal/codec"
"github.com/noahlann/nnet/internal/request"
"github.com/noahlann/nnet/internal/response"
ctxpkg "github.com/noahlann/nnet/pkg/context"
)
// NewTestContext creates a test context with mock connection, request, and response
func NewTestContext(parentCtx context.Context, connID string) ctxpkg.Context {
if parentCtx == nil {
parentCtx = context.Background()
}
conn := NewMockConnection(connID)
req := request.New([]byte("test"), nil)
codecRegistry := codec.NewRegistry()
resp := response.New(conn, nil, codecRegistry, "json")
return ctxpkg.New(parentCtx, conn, req, resp)
}
// NewTestContextWithData creates a test context with custom request data
func NewTestContextWithData(parentCtx context.Context, connID string, data []byte) ctxpkg.Context {
if parentCtx == nil {
parentCtx = context.Background()
}
conn := NewMockConnection(connID)
req := request.New(data, nil)
codecRegistry := codec.NewRegistry()
resp := response.New(conn, nil, codecRegistry, "json")
return ctxpkg.New(parentCtx, conn, req, resp)
}