Help us shape the future of Go! Take the 2026 Go Developer Survey

testkit

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package testkit holds test doubles shared by this module's tests. It is production code by build tag and test support by intent: it lives under internal/ so nothing outside this module can depend on it.

Index

Constants

View Source
const FirstJournalEpoch uint64 = 1

FirstJournalEpoch is the epoch a fresh FullSession reports. It is exported so a test asserts against the fixture's declared value rather than a literal that happens to match, and it is FAR from residency's first residency epoch on purpose.

Variables

AllCapabilities is every capability Host requires of a launched session.

View Source
var ErrRigRefused = errors.New("testkit: the rig refused to launch")

ErrRigRefused is a stable cause for a rig that declines to launch.

Functions

func NewBareSession

func NewBareSession(id uuid.UUID) department.RigSession

NewBareSession returns a session with the identity and no capability at all.

func NewSessionWithout

func NewSessionWithout(id uuid.UUID, missing Capability) department.RigSession

NewSessionWithout returns a session with every capability EXCEPT the one named. It panics on an unknown capability rather than returning a session that quietly has everything, because a typo'd capability name in a test would otherwise produce a passing assertion about a rejection that never happened.

Types

type Capability

type Capability string

Capability names a capability FakeSession can be built with or without.

const (
	CapabilityIdleWaiter            Capability = "IdleWaiter"
	CapabilityLiveness              Capability = "Liveness"
	CapabilityReleaser              Capability = "Releaser"
	CapabilityPublicationSubscriber Capability = "PublicationSubscriber"
	CapabilityCommandApplier        Capability = "CommandApplier"
	CapabilityLeaseEpochReporter    Capability = "LeaseEpochReporter"
)

type FakeRig

type FakeRig struct {

	// Session is handed back by both operations. Nil means "return NewErr".
	Session department.RigSession

	// NewErr and RestoreErr, when set, are returned instead of a session.
	NewErr     error
	RestoreErr error
	// contains filtered or unexported fields
}

FakeRig is a department.Rig that records what it was asked for.

It is the CONSUMER of everything the adapter claims to propagate, which is the only counterparty an assertion about propagation may use. Asserting that the adapter's own getters return what was passed in proves the adapter can remember a value; it does not prove the value reached the thing that needs it. A sibling lane lost that distinction and shipped a record written into an envelope its reader could not see, having round-tripped it through the writer's own decoder.

Every recorded field's ZERO VALUE is distinct from what tests assert, so an assertion cannot pass because the fixture already held the answer.

func (*FakeRig) Creates

func (f *FakeRig) Creates() []department.RigCreateRequest

Creates returns every create request this rig received, in order.

func (*FakeRig) Launches

func (f *FakeRig) Launches() int

Launches reports how many times this rig was asked to produce a session by either operation. It is the ordering assertion's instrument: a rejection that must happen BEFORE a launch is proved by this staying at zero, not by an error being returned.

func (*FakeRig) NewSession

NewSession records the request and returns the configured session.

func (*FakeRig) RestoreSession

func (f *FakeRig) RestoreSession(_ context.Context, id uuid.UUID, request department.RigRestoreRequest) (department.RigSession, error)

RestoreSession records the request and returns the configured session.

func (*FakeRig) RestoredIDs

func (f *FakeRig) RestoredIDs() []uuid.UUID

RestoredIDs returns the Harness identity each restore was asked for.

func (*FakeRig) Restores

func (f *FakeRig) Restores() []department.RigRestoreRequest

Restores returns every restore request this rig received, in order.

type FullSession

type FullSession struct {
	// contains filtered or unexported fields
}

FullSession has every capability Host requires.

func NewFullSession

func NewFullSession(id uuid.UUID) *FullSession

NewFullSession returns a session with every capability.

func (FullSession) Applied

func (p FullSession) Applied() []department.RuntimeCommand

Applied reports every command this session was asked to apply.

func (FullSession) ApplyCommand

func (p FullSession) ApplyCommand(_ context.Context, command department.RuntimeCommand) error

ApplyCommand records the command it was asked to apply.

func (FullSession) Done

func (p FullSession) Done() <-chan struct{}

Done reports when the session has stopped.

func (FullSession) ID

func (p FullSession) ID() uuid.UUID

ID is Harness's identity for this session.

func (FullSession) LeaseEpoch

func (p FullSession) LeaseEpoch() (uint64, bool)

LeaseEpoch reports this runtime's journal lease epoch and whether it holds one.

func (FullSession) ReleaseResidency

func (p FullSession) ReleaseResidency(context.Context) error

ReleaseResidency records a nonterminal residency release.

func (FullSession) Released

func (p FullSession) Released() int

Released reports how many times residency was released.

func (FullSession) SetLeaseEpoch

func (p FullSession) SetLeaseEpoch(epoch uint64, held bool)

SetLeaseEpoch moves the reported grant. held false is the legitimate "this session is not wired to a lease that reports an epoch" answer, and it is settable so a test can exercise it rather than assuming the epoch is always there.

func (*FullSession) Stop

func (s *FullSession) Stop()

Stop closes the liveness channel, so Done reports a stopped runtime.

func (FullSession) SubscribeCommitted

func (p FullSession) SubscribeCommitted(_ context.Context, after sessionwire.EventID) (<-chan sessionwire.EnduringPublication, error)

SubscribeCommitted records the resume point and returns a closed channel.

func (FullSession) SubscribedAfter

func (p FullSession) SubscribedAfter() []sessionwire.EventID

SubscribedAfter reports the resume point of every subscription.

func (FullSession) WaitIdle

func (FullSession) WaitIdle(ctx context.Context) error

WaitIdle returns nil unless the context is already done, so a test can prove the adapter forwards a cancelled context rather than swallowing it.

Jump to

Keyboard shortcuts

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