Documentation
¶
Overview ¶
Package agenttest is an in-process HAPTIC agent: an httptest server that speaks pkg/dataplane/agent/api well enough to drive the controller's deployer without a container.
It models what the deployer reasons about — the path-keyed proved file set, the four plan ids, the fencing token, the runtime inventory — and records every apply for assertions. It executes no HAProxy commands and writes no files; the real agent's disk transaction is covered by the docker suite in tests/agent.
Index ¶
- Constants
- type Agent
- func (a *Agent) AcceptOp(kind string)
- func (a *Agent) Applies() []RecordedApply
- func (a *Agent) ConflictOnce(reason string)
- func (a *Agent) Content(path string) []byte
- func (a *Agent) FailOnce()
- func (a *Agent) FirePendingReload()
- func (a *Agent) MissingOnce(paths ...string)
- func (a *Agent) Password() string
- func (a *Agent) PlanPuts() []RecordedPlanPut
- func (a *Agent) PlanReads() int
- func (a *Agent) RejectOp(kind string)
- func (a *Agent) SetAppliedEpoch(epoch uint64)
- func (a *Agent) SetPendingDeletes(servers, backends []string)
- func (a *Agent) SetReloadPending(pending bool)
- func (a *Agent) State() api.State
- func (a *Agent) StateReads() int
- func (a *Agent) TamperFile(path string, content []byte)
- func (a *Agent) URL() string
- func (a *Agent) Username() string
- type Option
- func WithAPIVersion(version int) Option
- func WithAgentOps(ops ...string) Option
- func WithCredentials(username, password string) Option
- func WithHAProxyInfo(info api.HAProxyInfo) Option
- func WithInventory(inventory *api.Inventory) Option
- func WithPlanPutDelay(delay time.Duration) Option
- func WithoutFilePatches() Option
- func WithoutPlanEndpoint() Option
- func WithoutRuntimeBatches() Option
- func WithoutWorkerFence() Option
- type RecordedApply
- type RecordedPlanPut
Constants ¶
const ( DefaultUsername = "admin" DefaultPassword = "adminpwd" )
Default credentials, mirroring the chart's agent Secret.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is the fake. Every method is safe for concurrent use.
func (*Agent) Applies ¶
func (a *Agent) Applies() []RecordedApply
Applies returns every request the fake received, in order.
func (*Agent) ConflictOnce ¶
ConflictOnce makes the next apply answer this 409 reason and write nothing, which is what the agent does when its baseline moved between the caller's state read and its apply. The reason is one of prev_mismatch, stale_epoch or unknown_baseline.
func (*Agent) FailOnce ¶
func (a *Agent) FailOnce()
FailOnce makes the next apply answer 500 and write nothing, the way an agent that hit an internal error does. The caller sees a failure, not a judgement: nothing about the pod's state is known to have changed.
func (*Agent) FirePendingReload ¶
func (a *Agent) FirePendingReload()
FirePendingReload is the pacer firing: the worker re-executes from the applied file set, so the applied plan becomes the running one.
func (*Agent) MissingOnce ¶
MissingOnce makes the next apply answer 409 with these paths and write nothing, which is what the agent does when its tree does not hold a file the manifest declares and the caller did not send it.
func (*Agent) PlanPuts ¶
func (a *Agent) PlanPuts() []RecordedPlanPut
PlanPuts returns every plan blob upload the fake received, in order.
func (*Agent) PlanReads ¶
PlanReads is how many of those reads asked for the plan blob, which a controller that holds the plan leaves out.
func (*Agent) RejectOp ¶
RejectOp makes every apply carrying this op kind come back as a NACK, the way HAProxy refusing a runtime command does.
func (*Agent) SetAppliedEpoch ¶
SetAppliedEpoch raises the leader epoch the fake has accepted. The agent persists the applied token, so a pod a previous leader wrote to outranks a controller whose epoch counter is behind — every apply below it is a 409.
func (*Agent) SetPendingDeletes ¶
SetPendingDeletes seeds the deferred deletes this pod is still waiting to complete. A pod at the cap refuses another batch, so what the controller composes for it has to be judged against its own count.
func (*Agent) SetReloadPending ¶
SetReloadPending makes the fake behave as if a paced reload were already scheduled: files are written and coalesced, ops are ignored, and only the in-place ops run.
func (*Agent) State ¶
State is a snapshot of what the fake would report on /v1/state, blob included.
func (*Agent) StateReads ¶
StateReads is how many times /v1/state was answered, which is what a caller that caches per pod is measured by.
func (*Agent) TamperFile ¶
TamperFile rewrites path behind the fake's back, as something else in the pod would. Like the agent, the fake reports it only on a verified read.
type Option ¶
type Option func(*Agent)
Option customises the fake before it starts serving.
func WithAPIVersion ¶ added in v0.8.0
WithAPIVersion sets the contract version the fake reports.
func WithAgentOps ¶
WithAgentOps restricts the op kinds the fake claims to execute, so a test can drive the controller's version-skew path.
func WithCredentials ¶
WithCredentials sets the basic-auth pair the fake requires.
func WithHAProxyInfo ¶
func WithHAProxyInfo(info api.HAProxyInfo) Option
WithHAProxyInfo sets the worker identity the fake reports.
func WithInventory ¶
WithInventory seeds what the running worker has loaded.
func WithPlanPutDelay ¶
WithPlanPutDelay makes every PUT /v1/plan take this long before it is stored, and gives it up when the request's context ends first.
func WithoutFilePatches ¶
func WithoutFilePatches() Option
WithoutFilePatches makes the fake behave like an agent that predates File.Patch, so every changed file has to arrive whole.
func WithoutPlanEndpoint ¶
func WithoutPlanEndpoint() Option
WithoutPlanEndpoint makes the fake behave like an agent that predates PUT /v1/plan, so the blob has to ride the apply.
func WithoutRuntimeBatches ¶
func WithoutRuntimeBatches() Option
WithoutRuntimeBatches models an agent without complete multi-batch transactions.
func WithoutWorkerFence ¶
func WithoutWorkerFence() Option
WithoutWorkerFence models an agent that predates automatic-apply worker fencing.
type RecordedApply ¶
type RecordedApply struct {
Manifest api.Manifest
Parts map[string][]byte
Plan []byte
Status int
Result *api.ApplyResult
Conflict *api.Conflict
Missing []string
}
RecordedApply is one received apply and the answer it produced.
type RecordedPlanPut ¶
RecordedPlanPut is one PUT /v1/plan the fake received.