networktest

package
v0.14.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package networktest provides forwarding fakes, session harnesses, and state observers for tests that exercise the real networker session manager.

Index

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)

FindFreePort returns the next unblocked port, advancing through at most 10,000 candidates.

func (*FakePortChecker) IsPortUnavailable

func (f *FakePortChecker) IsPortUnavailable(port int32) bool

IsPortUnavailable reports whether BlockPort marked the port as unavailable.

func (*FakePortChecker) UnblockPort

func (f *FakePortChecker) UnblockPort(port int32)

UnblockPort marks a port as available.

type Harness

type Harness struct {
	Manager *networker.Manager
	// contains filtered or unexported fields
}

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

StartSession is a convenience method to start a port forward session.

type HarnessOption

type HarnessOption func(*harnessConfig)

HarnessOption configures a Harness.

func WithClock

func WithClock(clk timeutil.Clock) HarnessOption

WithClock injects a custom clock.

func WithLogger

func WithLogger(l logging.Logger) HarnessOption

WithLogger sets a custom logger.

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

ForwardResource records the request and returns the configured failure or an immediately ready tunnel whose error channel reports FailAfter, if set.

func (*StubResourceForwarder) RecordedOpts

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

ForwardStatic returns the configured failure or an immediately ready tunnel whose error channel reports FailAfter, if set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL