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

haproxytest

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: 10 Imported by: 0

Documentation

Overview

Package haproxytest serves an in-memory model of the HAProxy runtime over a worker stats socket and a master socket. It is the oracle the agent's unit and fault-simulation tests compare against; the real wire framing is pinned by the docker test, not here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	Profile   string
	Mode      string
	GUID      string
	Published bool
	Servers   []*Server
}

Backend is one proxy of the model.

type HAProxy

type HAProxy struct {
	// contains filtered or unexported fields
}

HAProxy is the model plus its two sockets.

func Start

func Start(tb testing.TB) *HAProxy

Start serves the model on two unix sockets in a short-named temp directory: tb.TempDir() embeds the test name and a unix socket path is capped at 108 bytes, so a long subtest name would fail bind(2).

func (*HAProxy) HasBackend

func (h *HAProxy) HasBackend(name string) bool

HasBackend reports whether the model holds a backend of that name.

func (*HAProxy) MapEntries

func (h *HAProxy) MapEntries(path string) []MapEntry

MapEntries copies one map file's contents.

func (*HAProxy) MasterSocket

func (h *HAProxy) MasterSocket() string

MasterSocket carries reload and show proc.

func (*HAProxy) Sent

func (h *HAProxy) Sent() []string

Sent returns the commands the agent has issued so far.

func (*HAProxy) ServerNames

func (h *HAProxy) ServerNames(backend string) []string

ServerNames lists the servers a backend holds, empty when it does not exist.

func (*HAProxy) StopMaster

func (h *HAProxy) StopMaster()

StopMaster closes the master socket, which is what the agent sees while the HAProxy container is restarting: reload and show proc fail at the transport, with no verdict on any configuration.

func (*HAProxy) With

func (h *HAProxy) With(fn func(m *Model))

With runs fn against the model under the lock the socket goroutines hold.

func (*HAProxy) WorkerSocket

func (h *HAProxy) WorkerSocket() string

WorkerSocket is the stats socket every runtime command goes to.

type MapEntry

type MapEntry struct {
	Key   string
	Value string
}

MapEntry is one key/value pair of a map file, duplicates included.

type Model

type Model struct {
	Version             string
	Pid                 int
	StartTimeUnixMicros int64
	Backends            map[string]*Backend
	Maps                map[string][]MapEntry
	Certs               map[string]string
	CAFiles             map[string]string
	CRLFiles            map[string]string
	CRTLists            map[string][]string

	// ProbeConnections and TrafficConnections are the conn_tot counters of
	// the `status` and `http-tcp` frontends that `show stat` reports.
	ProbeConnections   uint64
	TrafficConnections uint64
	// ReloadFails makes the master `reload` answer Success=0.
	ReloadFails bool
	// ReloadLog is the startup log a reload returns.
	ReloadLog string
	// Commands records every command the agent sent, in order.
	Commands []string
	// BlockedServers makes `wait … srv-removable` expire for a server, the way
	// an in-flight request does.
	BlockedServers map[string]bool
	// Reject answers the matching command with an error instead of running it.
	Reject func(command string) (message string, rejected bool)
	// OnReload installs the state a newly started worker inherits from its
	// config file. Runtime-only objects are gone by the time it runs.
	OnReload func(m *Model)
	// contains filtered or unexported fields
}

Model is everything the fake knows. A test reaches it only through HAProxy.With, which holds the lock the socket goroutines take.

type Server

type Server struct {
	Name    string
	Address string
	Weight  int
	Maxconn int
	State   string
	Enabled bool
	Health  bool
}

Server is one server of a backend.

Jump to

Keyboard shortcuts

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