Documentation
¶
Overview ¶
Package exttesting provides in-process test utilities for Productize extension authors.
TestHarness simulates the host side of the extension subprocess protocol, letting authors exercise their extension logic without a running Productize instance. MockTransport provides connected in-memory transport pairs for unit tests that operate at the message level.
Quick start ¶
harness := exttesting.NewTestHarness(exttesting.HarnessOptions{
GrantedCapabilities: []extension.Capability{extension.CapabilityRunMutate},
})
ext := extension.New("my-ext", "0.1.0").
OnRunPostShutdown(func(
ctx context.Context,
hook extension.HookContext,
payload extension.RunPostShutdownPayload,
) error {
return nil
})
errCh := harness.Run(context.Background(), ext)
resp, _ := harness.Initialize(ctx, extension.InitializeRequestIdentity{
Name: "my-ext", Version: "0.1.0", Source: "workspace",
})
_ = harness.Shutdown(ctx, extension.ShutdownRequest{Reason: "test"})
<-errCh
Index ¶
- func NewMockTransportPair() (*MockTransport, *MockTransport)
- func NewMockTransportPairWithBuffer(buffer int) (*MockTransport, *MockTransport)
- func SortedHostCalls(calls []HostCall) []string
- type HarnessOptions
- type HostCall
- type HostHandler
- type MockTransport
- func (m *MockTransport) Close() error
- func (m *MockTransport) ReadMessage() (extension.Message, error)
- func (m *MockTransport) Receive(ctx context.Context) (extension.Message, error)
- func (m *MockTransport) Send(ctx context.Context, message extension.Message) error
- func (m *MockTransport) WriteMessage(message extension.Message) error
- type TestHarness
- func (h *TestHarness) DispatchHook(ctx context.Context, invocationID string, hook extension.HookInfo, payload any) (*extension.ExecuteHookResponse, error)
- func (h *TestHarness) HandleHostMethod(method string, handler HostHandler)
- func (h *TestHarness) HealthCheck(ctx context.Context) (*extension.HealthCheckResponse, error)
- func (h *TestHarness) HostCalls() []HostCall
- func (h *TestHarness) Initialize(ctx context.Context, identity extension.InitializeRequestIdentity) (*extension.InitializeResponse, error)
- func (h *TestHarness) Run(ctx context.Context, ext *extension.Extension) <-chan error
- func (h *TestHarness) SendEvent(ctx context.Context, event events.Event) error
- func (h *TestHarness) Shutdown(ctx context.Context, req extension.ShutdownRequest) (*extension.ShutdownResponse, error)
- func (h *TestHarness) Transport() extension.Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMockTransportPair ¶
func NewMockTransportPair() (*MockTransport, *MockTransport)
NewMockTransportPair creates a connected in-memory transport pair.
func NewMockTransportPairWithBuffer ¶
func NewMockTransportPairWithBuffer(buffer int) (*MockTransport, *MockTransport)
NewMockTransportPairWithBuffer creates a connected in-memory transport pair with the provided per-link buffer.
func SortedHostCalls ¶
SortedHostCalls returns the recorded Host API methods in lexical order.
Types ¶
type HarnessOptions ¶
type HarnessOptions struct {
ProtocolVersion string
SupportedProtocolVersions []string
ProductizeVersion string
Source string
GrantedCapabilities []extension.Capability
Runtime extension.InitializeRuntime
}
HarnessOptions configures the host-side initialize request defaults.
type HostCall ¶
type HostCall struct {
Method string
Params json.RawMessage
}
HostCall records one Host API request emitted by the extension.
type HostHandler ¶
HostHandler serves one Host API method inside the test harness.
type MockTransport ¶
type MockTransport struct {
// contains filtered or unexported fields
}
MockTransport is an in-memory message transport used by SDK tests.
func (*MockTransport) Close ¶
func (m *MockTransport) Close() error
Close closes this transport endpoint.
func (*MockTransport) ReadMessage ¶
func (m *MockTransport) ReadMessage() (extension.Message, error)
ReadMessage reads one queued message.
func (*MockTransport) WriteMessage ¶
func (m *MockTransport) WriteMessage(message extension.Message) error
WriteMessage enqueues one message for the peer transport.
type TestHarness ¶
type TestHarness struct {
// contains filtered or unexported fields
}
TestHarness simulates the Productize host for in-process SDK tests.
func NewTestHarness ¶
func NewTestHarness(options HarnessOptions) *TestHarness
NewTestHarness constructs a new in-process host harness.
func (*TestHarness) DispatchHook ¶
func (h *TestHarness) DispatchHook( ctx context.Context, invocationID string, hook extension.HookInfo, payload any, ) (*extension.ExecuteHookResponse, error)
DispatchHook issues one execute_hook request against the running extension.
func (*TestHarness) HandleHostMethod ¶
func (h *TestHarness) HandleHostMethod(method string, handler HostHandler)
HandleHostMethod registers a Host API method handler.
func (*TestHarness) HealthCheck ¶
func (h *TestHarness) HealthCheck(ctx context.Context) (*extension.HealthCheckResponse, error)
HealthCheck issues one health_check request against the running extension.
func (*TestHarness) HostCalls ¶
func (h *TestHarness) HostCalls() []HostCall
HostCalls returns the Host API calls emitted by the extension so far.
func (*TestHarness) Initialize ¶
func (h *TestHarness) Initialize( ctx context.Context, identity extension.InitializeRequestIdentity, ) (*extension.InitializeResponse, error)
Initialize performs the host-initiated initialize handshake.
func (*TestHarness) SendEvent ¶
SendEvent issues one on_event request against the running extension.
func (*TestHarness) Shutdown ¶
func (h *TestHarness) Shutdown( ctx context.Context, req extension.ShutdownRequest, ) (*extension.ShutdownResponse, error)
Shutdown issues one shutdown request against the running extension.
func (*TestHarness) Transport ¶
func (h *TestHarness) Transport() extension.Transport
Transport returns the extension-side transport to pass into the SDK.