Documentation
¶
Index ¶
- func ContextWithCancel(ctx context.Context) (*types.PluginContext, context.CancelFunc)
- func ContextWithCancelFrom(h *Harness) *types.PluginContext
- func Line(content string, opts ...LineOption) string
- func MultiSourceBuilder(sourceIDs ...string) logs.SourceBuilderFunc
- func SingleSourceBuilder(sourceID string, labels map[string]string) logs.SourceBuilderFunc
- type Harness
- func (h *Harness) AssertEventTypes(expected ...logs.LogStreamEventType)
- func (h *Harness) Close()
- func (h *Harness) CloseSession(sessionID string)
- func (h *Harness) CloseSource(sourceID string)
- func (h *Harness) CreateSession(resourceKey string, opts ...SessionOption) *logs.LogSession
- func (h *Harness) FeedLine(sourceID string, line string)
- func (h *Harness) GetSession(sessionID string) *logs.LogSession
- func (h *Harness) Manager() *logs.Manager
- func (h *Harness) Output() *RecordingOutput
- func (h *Harness) WaitForEvent(eventType logs.LogStreamEventType, timeout time.Duration) *logs.LogStreamEvent
- func (h *Harness) WaitForLines(count int, timeout time.Duration) []logs.LogLine
- func (h *Harness) WaitForStatus(status logs.LogSessionStatus, timeout time.Duration) bool
- type HarnessOption
- type LineOption
- type RecordingOutput
- func (r *RecordingOutput) Events() []logs.LogStreamEvent
- func (r *RecordingOutput) Lines() []logs.LogLine
- func (r *RecordingOutput) OnEvent(_ string, event logs.LogStreamEvent)
- func (r *RecordingOutput) OnLine(line logs.LogLine)
- func (r *RecordingOutput) RecordEvent(event logs.LogStreamEvent)
- func (r *RecordingOutput) RecordLine(line logs.LogLine)
- func (r *RecordingOutput) RecordStatus(status logs.LogSessionStatus)
- func (r *RecordingOutput) Statuses() []logs.LogSessionStatus
- func (r *RecordingOutput) WaitForEvent(eventType logs.LogStreamEventType, timeout time.Duration) *logs.LogStreamEvent
- func (r *RecordingOutput) WaitForLines(count int, timeout time.Duration) []logs.LogLine
- func (r *RecordingOutput) WaitForStatus(status logs.LogSessionStatus, timeout time.Duration) bool
- type SessionOption
- type TestLogSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithCancel ¶
func ContextWithCancel(ctx context.Context) (*types.PluginContext, context.CancelFunc)
ContextWithCancel returns a PluginContext wrapping a cancellable context.
func ContextWithCancelFrom ¶
func ContextWithCancelFrom(h *Harness) *types.PluginContext
ContextWithCancelFrom returns a PluginContext using the harness's context.
func Line ¶
func Line(content string, opts ...LineOption) string
Line creates a log line string with optional timestamp prefix.
func MultiSourceBuilder ¶
func MultiSourceBuilder(sourceIDs ...string) logs.SourceBuilderFunc
MultiSourceBuilder returns a SourceBuilderFunc that produces sources with the given IDs.
func SingleSourceBuilder ¶
func SingleSourceBuilder(sourceID string, labels map[string]string) logs.SourceBuilderFunc
SourceBuilder returns a SourceBuilderFunc that produces a single source with the given ID and labels.
Types ¶
type Harness ¶
type Harness struct {
// contains filtered or unexported fields
}
Harness provides a fluent test DSL for testing the logs Manager. It wraps a real Manager with TestLogSources wired in.
func Mount ¶
func Mount(t *testing.T, opts ...HarnessOption) *Harness
Mount creates a new Harness with a real Manager and TestLogSources wired in. The harness is cleaned up automatically via t.Cleanup.
func (*Harness) AssertEventTypes ¶
func (h *Harness) AssertEventTypes(expected ...logs.LogStreamEventType)
AssertEventTypes checks that all expected event types have been recorded, in order.
func (*Harness) Close ¶
func (h *Harness) Close()
Close shuts down the harness by closing all sessions and waiting for goroutines.
func (*Harness) CloseSession ¶
CloseSession closes the given session.
func (*Harness) CloseSource ¶
CloseSource closes the Lines channel for the named source, ending its stream. It is safe to call multiple times — the close-of-closed-channel panic is recovered.
func (*Harness) CreateSession ¶
func (h *Harness) CreateSession(resourceKey string, opts ...SessionOption) *logs.LogSession
CreateSession creates a log session for the given resource key.
func (*Harness) FeedLine ¶
FeedLine sends a line to the named source. It is safe to call after CloseSource — the send-on-closed-channel panic is recovered.
func (*Harness) GetSession ¶
func (h *Harness) GetSession(sessionID string) *logs.LogSession
GetSession retrieves the current state of a session.
func (*Harness) Output ¶
func (h *Harness) Output() *RecordingOutput
Output returns the recording output for direct inspection.
func (*Harness) WaitForEvent ¶
func (h *Harness) WaitForEvent(eventType logs.LogStreamEventType, timeout time.Duration) *logs.LogStreamEvent
WaitForEvent waits until an event of the given type is received.
func (*Harness) WaitForLines ¶
WaitForLines waits until at least count lines have been received.
func (*Harness) WaitForStatus ¶
WaitForStatus waits until the given status has been recorded.
type HarnessOption ¶
type HarnessOption func(*harnessConfig)
HarnessOption configures the Harness.
func WithResolver ¶
func WithResolver(resourceKey string, resolver logs.SourceResolver) HarnessOption
WithResolver adds a source resolver for a resource key.
func WithSource ¶
func WithSource(sourceID string, src *TestLogSource) HarnessOption
WithSource adds a named test source to the harness. The source ID is used as both the handler key and source ID.
type LineOption ¶
type LineOption func(*lineConfig)
LineOption configures a test log line.
func WithLevel ¶
func WithLevel(_ logs.LogLevel) LineOption
WithLevel is intentionally a no-op — level is set server-side by the handler, not embedded in line content. This option exists for test DSL completeness. TODO: Wire to lineConfig.level when LogLine-level filtering is supported.
func WithTimestamp ¶
func WithTimestamp(t time.Time) LineOption
WithTimestamp sets the timestamp for a test line.
type RecordingOutput ¶
type RecordingOutput struct {
// contains filtered or unexported fields
}
RecordingOutput is a thread-safe recorder for all output from a log manager. It captures log lines and stream events, and provides waiters for test assertions.
func NewRecordingOutput ¶
func NewRecordingOutput() *RecordingOutput
NewRecordingOutput creates a new RecordingOutput.
func (*RecordingOutput) Events ¶
func (r *RecordingOutput) Events() []logs.LogStreamEvent
Events returns a copy of all recorded events.
func (*RecordingOutput) Lines ¶
func (r *RecordingOutput) Lines() []logs.LogLine
Lines returns a copy of all recorded lines.
func (*RecordingOutput) OnEvent ¶
func (r *RecordingOutput) OnEvent(_ string, event logs.LogStreamEvent)
OnEvent satisfies the logs.OutputSink interface.
func (*RecordingOutput) OnLine ¶
func (r *RecordingOutput) OnLine(line logs.LogLine)
OnLine satisfies the logs.OutputSink interface.
func (*RecordingOutput) RecordEvent ¶
func (r *RecordingOutput) RecordEvent(event logs.LogStreamEvent)
RecordEvent records a stream event. Thread-safe.
func (*RecordingOutput) RecordLine ¶
func (r *RecordingOutput) RecordLine(line logs.LogLine)
RecordLine records a log line. Thread-safe.
func (*RecordingOutput) RecordStatus ¶
func (r *RecordingOutput) RecordStatus(status logs.LogSessionStatus)
RecordStatus records a session status. Thread-safe.
func (*RecordingOutput) Statuses ¶
func (r *RecordingOutput) Statuses() []logs.LogSessionStatus
Statuses returns a copy of all recorded statuses.
func (*RecordingOutput) WaitForEvent ¶
func (r *RecordingOutput) WaitForEvent(eventType logs.LogStreamEventType, timeout time.Duration) *logs.LogStreamEvent
WaitForEvent waits until an event of the given type is recorded, or times out.
func (*RecordingOutput) WaitForLines ¶
WaitForLines waits until at least count lines have been recorded, or times out.
func (*RecordingOutput) WaitForStatus ¶
func (r *RecordingOutput) WaitForStatus(status logs.LogSessionStatus, timeout time.Duration) bool
WaitForStatus waits until a session with the given status is recorded, or times out.
type SessionOption ¶
type SessionOption func(*sessionConfig)
SessionOption configures session creation in the harness.
func WithResourceData ¶
func WithResourceData(data map[string]interface{}) SessionOption
WithResourceData sets the resource data for session creation.
func WithResourceID ¶
func WithResourceID(id string) SessionOption
WithResourceID sets the resource ID for session creation.
func WithSessionOptions ¶
func WithSessionOptions(opts logs.LogSessionOptions) SessionOption
WithSessionOptions sets the session options.
type TestLogSource ¶
type TestLogSource struct {
// Lines feeds log lines to the source. Close to end the stream.
Lines chan string
// Events injects stream events (reconnect, error, etc.).
Events chan logs.LogStreamEvent
// ErrOnConnect simulates a connection failure.
ErrOnConnect error
// ConnectDelay simulates a slow connection.
ConnectDelay time.Duration
}
TestLogSource is a programmable log source for testing. Feed lines via the Lines channel and inject events via the Events channel.
func NewTestLogSource ¶
func NewTestLogSource() *TestLogSource
NewTestLogSource creates a TestLogSource with buffered channels.
func (*TestLogSource) HandlerFunc ¶
func (s *TestLogSource) HandlerFunc() logs.LogHandlerFunc
HandlerFunc returns a LogHandlerFunc that reads from this test source. The returned reader streams lines from the Lines channel, one per line. The reader respects context cancellation via the PluginContext so that goroutines unblock when the session is closed.
func (*TestLogSource) ReaderFunc ¶
func (s *TestLogSource) ReaderFunc(pctx *types.PluginContext) (io.ReadCloser, error)
ReaderFunc returns an io.ReadCloser that reads from this source's Lines channel. The reader respects the PluginContext for cancellation.