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

fleettest

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package fleettest holds an in-memory double of the stores the authoring and fleet domains write through (policy.Store, fleet.Store, and the compiler's render transaction), for tests of those domains and of the transports above them. It keeps the same version, reference, and resolution semantics as the Postgres store, which is tested in internal/store; a transaction here is a snapshot restored on failure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Directives

type Directives struct {
	Err error
	// contains filtered or unexported fields
}

Directives records the reconnects directed through it in order, in place of the notification bridge. Err, when set, is returned instead.

func (*Directives) DirectReconnect

func (d *Directives) DirectReconnect(_ context.Context, id identity.WorkloadID) error

DirectReconnect implements fleet.Directives.

func (*Directives) Reconnects

func (d *Directives) Reconnects() []identity.WorkloadID

Reconnects returns the workloads directed to reconnect so far.

type MemStore

type MemStore struct {
	Workloads     []registry.Workload
	Services      []policy.Service
	AddressGroups []policy.AddressGroup
	Rulesets      []policy.Ruleset
	Policies      map[identity.WorkloadID]*innerwallv1.WorkloadPolicy
	ModeChanges   []*fleet.ModeChangeRecord
	// Gaps are the gaps retirements wrote, by workload, and Ended the
	// workloads whose stream a retirement directed ended, in order.
	Gaps  map[identity.WorkloadID][]flowstore.Gap
	Ended []identity.WorkloadID
	// LastFlowReportAt and Processes are what a retirement's silence
	// derivation reads for a workload, set by a test.
	LastFlowReportAt map[identity.WorkloadID]time.Time
	Processes        map[identity.WorkloadID]registry.AgentProcess
	// Writes counts every write that reached the store, so a test can
	// assert that a read left nothing behind.
	Writes int
	// AfterResolve, when set, runs inside a mode change after its inputs
	// were loaded and before the modes are flipped, with the store lock
	// released, so a test can move labels underneath the change.
	AfterResolve func()
	// AfterRulesetsRead, when set, runs once, the next time the rulesets
	// are read (alone or as part of the render state), with the store
	// lock released, so a test can land a write between that read and
	// anything the caller reads after it.
	AfterRulesetsRead func()
	// contains filtered or unexported fields
}

MemStore is the double. Exported fields are fixtures a test sets and reads; the methods keep them consistent the way the store would.

func New

func New() *MemStore

New returns an empty store.

func (*MemStore) CountWorkloadsByStatus added in v0.2.0

func (m *MemStore) CountWorkloadsByStatus(context.Context) ([]readmodel.StatusCount, error)

CountWorkloadsByStatus implements readmodel.Store: a pair no workload holds is absent, as it is from the Postgres statement.

func (*MemStore) CreateAddressGroup

func (m *MemStore) CreateAddressGroup(_ context.Context, g *policy.AddressGroup) error

CreateAddressGroup implements policy.Store.

func (*MemStore) CreateRuleset

func (m *MemStore) CreateRuleset(_ context.Context, rs *policy.Ruleset) error

CreateRuleset implements policy.Store.

func (*MemStore) CreateService

func (m *MemStore) CreateService(_ context.Context, s *policy.Service) error

CreateService implements policy.Store.

func (*MemStore) DeleteAddressGroup

func (m *MemStore) DeleteAddressGroup(_ context.Context, id uuid.UUID, expect string) error

DeleteAddressGroup implements policy.Store.

func (*MemStore) DeleteRuleset

func (m *MemStore) DeleteRuleset(_ context.Context, id uuid.UUID, expect string) error

DeleteRuleset implements policy.Store.

func (*MemStore) DeleteService

func (m *MemStore) DeleteService(_ context.Context, id uuid.UUID, expect string) error

DeleteService implements policy.Store.

func (*MemStore) GetAddressGroup

func (m *MemStore) GetAddressGroup(_ context.Context, id uuid.UUID) (*policy.AddressGroup, error)

GetAddressGroup implements policy.Store.

func (*MemStore) GetRuleset

func (m *MemStore) GetRuleset(_ context.Context, id uuid.UUID) (*policy.Ruleset, error)

GetRuleset implements policy.Store.

func (*MemStore) GetService

func (m *MemStore) GetService(_ context.Context, id uuid.UUID) (*policy.Service, error)

GetService implements policy.Store.

func (*MemStore) GetWorkloadPolicy

func (m *MemStore) GetWorkloadPolicy(_ context.Context, id identity.WorkloadID) (*innerwallv1.WorkloadPolicy, error)

GetWorkloadPolicy returns a workload's rendered policy, or nil.

func (*MemStore) GetWorkloadRecord

func (m *MemStore) GetWorkloadRecord(_ context.Context, id identity.WorkloadID) (*readmodel.WorkloadRecord, error)

GetWorkloadRecord implements readmodel.Store.

func (*MemStore) ListAddressGroups

func (m *MemStore) ListAddressGroups(context.Context) ([]policy.AddressGroup, error)

ListAddressGroups implements policy.Store.

func (*MemStore) ListRulesets

func (m *MemStore) ListRulesets(context.Context) ([]policy.Ruleset, error)

ListRulesets implements policy.Store.

func (*MemStore) ListServices

func (m *MemStore) ListServices(context.Context) ([]policy.Service, error)

ListServices implements policy.Store.

func (*MemStore) ListWorkloadLabelIndex

func (m *MemStore) ListWorkloadLabelIndex(context.Context) (map[identity.WorkloadID]map[string]string, error)

ListWorkloadLabelIndex implements readmodel.Store.

func (*MemStore) ListWorkloadPage

ListWorkloadPage implements readmodel.Store with the fleet order and the cursor semantics of the Postgres statement.

func (*MemStore) ListWorkloads

func (m *MemStore) ListWorkloads(context.Context) ([]registry.Workload, error)

ListWorkloads implements fleet.Store.

func (*MemStore) LoadRenderState

LoadRenderState implements fleet.Store.

func (*MemStore) ModeChangeTx

func (m *MemStore) ModeChangeTx(ctx context.Context, fn func(ctx context.Context, tx fleet.ModeChangeTx) error) error

ModeChangeTx implements fleet.Store.

func (*MemStore) RenderTx

func (m *MemStore) RenderTx(ctx context.Context, fn func(ctx context.Context, tx compiler.Tx) error) error

RenderTx implements compiler.Store.

func (*MemStore) ReplaceWorkloadLabels

func (m *MemStore) ReplaceWorkloadLabels(_ context.Context, id identity.WorkloadID, labels []registry.Label, expect string) error

ReplaceWorkloadLabels implements fleet.Store.

func (*MemStore) RetireTx added in v0.5.0

func (m *MemStore) RetireTx(ctx context.Context, fn func(ctx context.Context, tx fleet.RetireTx) error) error

RetireTx implements fleet.Store.

func (*MemStore) SetWorkloadLabels

func (m *MemStore) SetWorkloadLabels(ctx context.Context, id identity.WorkloadID, labels []registry.Label) error

SetWorkloadLabels replaces labels unconditionally, as a test fixture mutation.

func (*MemStore) UpdateAddressGroup

func (m *MemStore) UpdateAddressGroup(_ context.Context, g *policy.AddressGroup, expect string) error

UpdateAddressGroup implements policy.Store.

func (*MemStore) UpdateRuleset

func (m *MemStore) UpdateRuleset(_ context.Context, rs *policy.Ruleset, expect string) error

UpdateRuleset implements policy.Store.

func (*MemStore) UpdateService

func (m *MemStore) UpdateService(_ context.Context, s *policy.Service, expect string) error

UpdateService implements policy.Store.

func (*MemStore) Workload

func (m *MemStore) Workload(id identity.WorkloadID) *registry.Workload

Workload returns a copy of one workload, or nil.

type Renderer

type Renderer struct{ Engine *compiler.Engine }

Renderer adapts an engine over the store to the authoring service's Renderer.

func (Renderer) Render

func (r Renderer) Render(ctx context.Context) error

Render implements policy.Renderer.

Jump to

Keyboard shortcuts

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