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
- Variables
- func NewBareSession(id uuid.UUID) department.RigSession
- func NewSessionWithout(id uuid.UUID, missing Capability) department.RigSession
- type Capability
- type FakeRig
- func (f *FakeRig) Creates() []department.RigCreateRequest
- func (f *FakeRig) Launches() int
- func (f *FakeRig) NewSession(ctx context.Context, request department.RigCreateRequest) (department.RigSession, error)
- func (f *FakeRig) RestoreSession(ctx context.Context, id uuid.UUID, request department.RigRestoreRequest) (department.RigSession, error)
- func (f *FakeRig) RestoredIDs() []uuid.UUID
- func (f *FakeRig) Restores() []department.RigRestoreRequest
- type FullSession
- func (p FullSession) Applied() []department.RuntimeCommand
- func (p FullSession) ApplyCommand(_ context.Context, command department.RuntimeCommand) error
- func (p FullSession) Done() <-chan struct{}
- func (p FullSession) ID() uuid.UUID
- func (p FullSession) LeaseEpoch() (uint64, bool)
- func (p FullSession) ReleaseResidency(context.Context) error
- func (p FullSession) Released() int
- func (p FullSession) SetLeaseEpoch(epoch uint64, held bool)
- func (s *FullSession) Stop()
- func (p FullSession) SubscribeCommitted(_ context.Context, after sessionwire.EventID) (<-chan sessionwire.EnduringPublication, error)
- func (p FullSession) SubscribedAfter() []sessionwire.EventID
- func (FullSession) WaitIdle(ctx context.Context) error
Constants ¶
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 ¶
var AllCapabilities = []Capability{ CapabilityIdleWaiter, CapabilityLiveness, CapabilityReleaser, CapabilityPublicationSubscriber, CapabilityCommandApplier, CapabilityLeaseEpochReporter, }
AllCapabilities is every capability Host requires of a launched session.
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
// LaunchHook, when set, runs at the start of both operations — outside the
// rig's lock, with the launch's context — and its error is the launch's.
// It is how a test parks a launch, cooperatively or not.
LaunchHook func(context.Context) 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 ¶
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 ¶
func (f *FakeRig) NewSession(ctx context.Context, request department.RigCreateRequest) (department.RigSession, error)
NewSession records the request and returns the configured session.
func (*FakeRig) RestoreSession ¶
func (f *FakeRig) RestoreSession(ctx context.Context, id uuid.UUID, request department.RigRestoreRequest) (department.RigSession, error)
RestoreSession records the request and returns the configured session.
func (*FakeRig) RestoredIDs ¶
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) LeaseEpoch ¶
LeaseEpoch reports this runtime's journal lease epoch and whether it holds one.
func (FullSession) ReleaseResidency ¶
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 ¶
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.