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 ¶
- type Directives
- type MemStore
- func (m *MemStore) CountWorkloadsByStatus(context.Context) ([]readmodel.StatusCount, error)
- func (m *MemStore) CreateAddressGroup(_ context.Context, g *policy.AddressGroup) error
- func (m *MemStore) CreateRuleset(_ context.Context, rs *policy.Ruleset) error
- func (m *MemStore) CreateService(_ context.Context, s *policy.Service) error
- func (m *MemStore) DeleteAddressGroup(_ context.Context, id uuid.UUID, expect string) error
- func (m *MemStore) DeleteRuleset(_ context.Context, id uuid.UUID, expect string) error
- func (m *MemStore) DeleteService(_ context.Context, id uuid.UUID, expect string) error
- func (m *MemStore) GetAddressGroup(_ context.Context, id uuid.UUID) (*policy.AddressGroup, error)
- func (m *MemStore) GetRuleset(_ context.Context, id uuid.UUID) (*policy.Ruleset, error)
- func (m *MemStore) GetService(_ context.Context, id uuid.UUID) (*policy.Service, error)
- func (m *MemStore) GetWorkloadPolicy(_ context.Context, id identity.WorkloadID) (*innerwallv1.WorkloadPolicy, error)
- func (m *MemStore) GetWorkloadRecord(_ context.Context, id identity.WorkloadID) (*readmodel.WorkloadRecord, error)
- func (m *MemStore) ListAddressGroups(context.Context) ([]policy.AddressGroup, error)
- func (m *MemStore) ListRulesets(context.Context) ([]policy.Ruleset, error)
- func (m *MemStore) ListServices(context.Context) ([]policy.Service, error)
- func (m *MemStore) ListWorkloadLabelIndex(context.Context) (map[identity.WorkloadID]map[string]string, error)
- func (m *MemStore) ListWorkloadPage(_ context.Context, q readmodel.WorkloadPageQuery) ([]readmodel.WorkloadRecord, error)
- func (m *MemStore) ListWorkloads(context.Context) ([]registry.Workload, error)
- func (m *MemStore) LoadRenderState(context.Context) (*compiler.Inputs, map[identity.WorkloadID]*innerwallv1.WorkloadPolicy, error)
- func (m *MemStore) ModeChangeTx(ctx context.Context, fn func(ctx context.Context, tx fleet.ModeChangeTx) error) error
- func (m *MemStore) RenderTx(ctx context.Context, fn func(ctx context.Context, tx compiler.Tx) error) error
- func (m *MemStore) ReplaceWorkloadLabels(_ context.Context, id identity.WorkloadID, labels []registry.Label, ...) error
- func (m *MemStore) RetireTx(ctx context.Context, fn func(ctx context.Context, tx fleet.RetireTx) error) error
- func (m *MemStore) SetWorkloadLabels(ctx context.Context, id identity.WorkloadID, labels []registry.Label) error
- func (m *MemStore) UpdateAddressGroup(_ context.Context, g *policy.AddressGroup, expect string) error
- func (m *MemStore) UpdateRuleset(_ context.Context, rs *policy.Ruleset, expect string) error
- func (m *MemStore) UpdateService(_ context.Context, s *policy.Service, expect string) error
- func (m *MemStore) Workload(id identity.WorkloadID) *registry.Workload
- type Renderer
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 (*MemStore) CountWorkloadsByStatus ¶ added in v0.2.0
CountWorkloadsByStatus implements readmodel.Store: a pair no workload holds is absent, as it is from the Postgres statement.
func (*MemStore) CreateAddressGroup ¶
CreateAddressGroup implements policy.Store.
func (*MemStore) CreateRuleset ¶
CreateRuleset implements policy.Store.
func (*MemStore) CreateService ¶
CreateService implements policy.Store.
func (*MemStore) DeleteAddressGroup ¶
DeleteAddressGroup implements policy.Store.
func (*MemStore) DeleteRuleset ¶
DeleteRuleset implements policy.Store.
func (*MemStore) DeleteService ¶
DeleteService implements policy.Store.
func (*MemStore) GetAddressGroup ¶
GetAddressGroup implements policy.Store.
func (*MemStore) GetRuleset ¶
GetRuleset implements policy.Store.
func (*MemStore) GetService ¶
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 ¶
ListAddressGroups implements policy.Store.
func (*MemStore) ListRulesets ¶
ListRulesets implements policy.Store.
func (*MemStore) ListServices ¶
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 ¶
func (m *MemStore) ListWorkloadPage(_ context.Context, q readmodel.WorkloadPageQuery) ([]readmodel.WorkloadRecord, error)
ListWorkloadPage implements readmodel.Store with the fleet order and the cursor semantics of the Postgres statement.
func (*MemStore) ListWorkloads ¶
ListWorkloads implements fleet.Store.
func (*MemStore) LoadRenderState ¶
func (m *MemStore) LoadRenderState(context.Context) (*compiler.Inputs, map[identity.WorkloadID]*innerwallv1.WorkloadPolicy, error)
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 ¶
UpdateRuleset implements policy.Store.
func (*MemStore) UpdateService ¶
UpdateService implements policy.Store.