Documentation
¶
Index ¶
- func TestPluginCtx() *types.PluginContext
- type FakePortChecker
- type Harness
- func (h *Harness) CloseSession(sessionID string) (*networker.PortForwardSession, error)
- func (h *Harness) GetSession(sessionID string) (*networker.PortForwardSession, error)
- func (h *Harness) ListSessions() ([]*networker.PortForwardSession, error)
- func (h *Harness) StartSession(opts networker.PortForwardSessionOptions) (*networker.PortForwardSession, error)
- type HarnessOption
- func WithClock(clk timeutil.Clock) HarnessOption
- func WithLogger(l logging.Logger) HarnessOption
- func WithPortChecker(pc networker.PortChecker) HarnessOption
- func WithResourceForwarder(key string, f networker.ResourceForwarder) HarnessOption
- func WithStaticForwarder(key string, f networker.StaticForwarder) HarnessOption
- type RecordingObserver
- type SessionStateChange
- type StubResourceForwarder
- type StubStaticForwarder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TestPluginCtx ¶
func TestPluginCtx() *types.PluginContext
TestPluginCtx returns a minimal PluginContext for use in tests outside the harness.
Types ¶
type FakePortChecker ¶
type FakePortChecker struct {
// contains filtered or unexported fields
}
FakePortChecker provides deterministic port assignment for tests.
func NewFakePortChecker ¶
func NewFakePortChecker(startPort int32) *FakePortChecker
NewFakePortChecker creates a FakePortChecker that assigns ports starting at startPort.
func (*FakePortChecker) BlockPort ¶
func (f *FakePortChecker) BlockPort(port int32)
BlockPort marks a port as unavailable.
func (*FakePortChecker) FindFreePort ¶
func (f *FakePortChecker) FindFreePort() (int32, error)
func (*FakePortChecker) IsPortUnavailable ¶
func (f *FakePortChecker) IsPortUnavailable(port int32) bool
func (*FakePortChecker) UnblockPort ¶
func (f *FakePortChecker) UnblockPort(port int32)
UnblockPort marks a port as available.
type Harness ¶
Harness is a test DSL wrapping a real networker.Manager.
func Mount ¶
func Mount(t *testing.T, opts ...HarnessOption) *Harness
Mount creates a new Harness. Cleaned up via t.Cleanup().
func (*Harness) CloseSession ¶
func (h *Harness) CloseSession(sessionID string) (*networker.PortForwardSession, error)
CloseSession closes a port forward session by ID.
func (*Harness) GetSession ¶
func (h *Harness) GetSession(sessionID string) (*networker.PortForwardSession, error)
GetSession retrieves a session by ID.
func (*Harness) ListSessions ¶
func (h *Harness) ListSessions() ([]*networker.PortForwardSession, error)
ListSessions returns all sessions.
func (*Harness) StartSession ¶
func (h *Harness) StartSession(opts networker.PortForwardSessionOptions) (*networker.PortForwardSession, error)
StartSession is a convenience method to start a port forward session.
type HarnessOption ¶
type HarnessOption func(*harnessConfig)
HarnessOption configures a Harness.
func WithPortChecker ¶
func WithPortChecker(pc networker.PortChecker) HarnessOption
WithPortChecker overrides the port checker.
func WithResourceForwarder ¶
func WithResourceForwarder(key string, f networker.ResourceForwarder) HarnessOption
WithResourceForwarder registers a resource forwarder.
func WithStaticForwarder ¶
func WithStaticForwarder(key string, f networker.StaticForwarder) HarnessOption
WithStaticForwarder registers a static forwarder.
type RecordingObserver ¶
type RecordingObserver struct {
// contains filtered or unexported fields
}
RecordingObserver tracks session state changes for assertions.
func NewRecordingObserver ¶
func NewRecordingObserver() *RecordingObserver
NewRecordingObserver creates a new RecordingObserver.
func (*RecordingObserver) Changes ¶
func (r *RecordingObserver) Changes() []SessionStateChange
Changes returns a copy of all recorded changes.
func (*RecordingObserver) Record ¶
func (r *RecordingObserver) Record(sessionID string, state networker.SessionState)
Record adds a state change to the log.
func (*RecordingObserver) WaitForState ¶
func (r *RecordingObserver) WaitForState(sessionID string, state networker.SessionState, timeout time.Duration) *SessionStateChange
WaitForState blocks until a change with the given state for the given session is recorded.
type SessionStateChange ¶
type SessionStateChange struct {
SessionID string
State networker.SessionState
Timestamp time.Time
}
SessionStateChange records a state transition.
type StubResourceForwarder ¶
type StubResourceForwarder struct {
// FailWith causes ForwardResource to return this error immediately.
FailWith error
// FailAfter causes the ErrCh to emit this error after Ready closes.
// Simulates a tunnel that starts successfully but dies later.
FailAfter error
// contains filtered or unexported fields
}
StubResourceForwarder implements networker.ResourceForwarder with configurable behavior.
func (*StubResourceForwarder) Calls ¶
func (s *StubResourceForwarder) Calls() int
Calls returns the number of times ForwardResource was called.
func (*StubResourceForwarder) ForwardResource ¶
func (s *StubResourceForwarder) ForwardResource( _ context.Context, _ *types.PluginContext, opts networker.ResourcePortForwardHandlerOpts, ) (*networker.ForwarderResult, error)
func (*StubResourceForwarder) RecordedOpts ¶
func (s *StubResourceForwarder) RecordedOpts() []networker.ResourcePortForwardHandlerOpts
RecordedOpts returns all opts passed to ForwardResource.
type StubStaticForwarder ¶
type StubStaticForwarder struct {
// FailWith causes ForwardStatic to return this error immediately.
FailWith error
// FailAfter causes the ErrCh to emit this error after Ready closes.
// Simulates a tunnel that starts successfully but dies later.
FailAfter error
// contains filtered or unexported fields
}
StubStaticForwarder implements networker.StaticForwarder with configurable behavior.
func (*StubStaticForwarder) Calls ¶
func (s *StubStaticForwarder) Calls() int
Calls returns the number of times ForwardStatic was called.
func (*StubStaticForwarder) ForwardStatic ¶
func (s *StubStaticForwarder) ForwardStatic( _ context.Context, _ *types.PluginContext, _ networker.StaticPortForwardHandlerOpts, ) (*networker.ForwarderResult, error)