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

agenttest

package
v0.9.0 Latest Latest
Warning

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

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

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

View Source
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 New

func New(tb testing.TB, opts ...Option) *Agent

New starts a fake agent on loopback and stops it when the test ends.

func (*Agent) AcceptOp

func (a *Agent) AcceptOp(kind string)

AcceptOp undoes RejectOp for this kind.

func (*Agent) Applies

func (a *Agent) Applies() []RecordedApply

Applies returns every request the fake received, in order.

func (*Agent) ConflictOnce

func (a *Agent) ConflictOnce(reason string)

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) Content

func (a *Agent) Content(path string) []byte

Content is what the fake holds at path, nil when it holds nothing there.

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

func (a *Agent) MissingOnce(paths ...string)

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) Password

func (a *Agent) Password() string

Password is the basic-auth password the fake requires.

func (*Agent) PlanPuts

func (a *Agent) PlanPuts() []RecordedPlanPut

PlanPuts returns every plan blob upload the fake received, in order.

func (*Agent) PlanReads

func (a *Agent) PlanReads() int

PlanReads is how many of those reads asked for the plan blob, which a controller that holds the plan leaves out.

func (*Agent) RejectOp

func (a *Agent) RejectOp(kind string)

RejectOp makes every apply carrying this op kind come back as a NACK, the way HAProxy refusing a runtime command does.

func (*Agent) SetAppliedEpoch

func (a *Agent) SetAppliedEpoch(epoch uint64)

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

func (a *Agent) SetPendingDeletes(servers, backends []string)

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

func (a *Agent) SetReloadPending(pending bool)

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

func (a *Agent) State() api.State

State is a snapshot of what the fake would report on /v1/state, blob included.

func (*Agent) StateReads

func (a *Agent) StateReads() int

StateReads is how many times /v1/state was answered, which is what a caller that caches per pod is measured by.

func (*Agent) TamperFile

func (a *Agent) TamperFile(path string, content []byte)

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.

func (*Agent) URL

func (a *Agent) URL() string

URL is the base URL a client.Config takes.

func (*Agent) Username

func (a *Agent) Username() string

Username and Password are the credentials the fake requires.

type Option

type Option func(*Agent)

Option customises the fake before it starts serving.

func WithAPIVersion added in v0.8.0

func WithAPIVersion(version int) Option

WithAPIVersion sets the contract version the fake reports.

func WithAgentOps

func WithAgentOps(ops ...string) Option

WithAgentOps restricts the op kinds the fake claims to execute, so a test can drive the controller's version-skew path.

func WithCredentials

func WithCredentials(username, password string) Option

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

func WithInventory(inventory *api.Inventory) Option

WithInventory seeds what the running worker has loaded.

func WithPlanPutDelay

func WithPlanPutDelay(delay time.Duration) Option

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

type RecordedPlanPut struct {
	PlanID string
	Proof  string
	Plan   []byte
}

RecordedPlanPut is one PUT /v1/plan the fake received.

Jump to

Keyboard shortcuts

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