Documentation
¶
Overview ¶
Package dataplanetest provides test doubles for pkg/dataplane.
Unit tests must never shell out to external binaries: the haproxy binary is not present on every dev machine (it has no Windows build at all), and exec-ing it makes tests slow and environment-dependent. Packages whose tests reach dataplane.DetectLocalVersion or semantic validation install the fake once per package:
func TestMain(m *testing.M) {
restore := dataplanetest.InstallFakeHAProxy()
code := m.Run()
restore()
os.Exit(code)
}
Installing per package (not per test) avoids restore-ordering hazards with t.Parallel. pkg/dataplane's own internal tests cannot import this package (cycle); they install an equivalent fake via dataplane.SetHAProxyExecutor directly.
Index ¶
Constants ¶
const DefaultFakeVersion = "3.2.0"
DefaultFakeVersion is the HAProxy version the fake reports by default. 3.2 matches versions.env's DEFAULT_HAPROXY so capability detection in tests mirrors the bundled HAProxy.
Variables ¶
This section is empty.
Functions ¶
func InstallFakeHAProxy ¶
func InstallFakeHAProxy(opts ...Option) (restore func())
InstallFakeHAProxy installs a dataplane.HAProxyExecutor that never executes an external process: `haproxy -v` reports DefaultFakeVersion and config checks succeed. It returns a restore function; call it (or let the process exit) when done.
Types ¶
type Option ¶
type Option func(*fakeExecutor)
Option customizes the fake executor.
func WithCheck ¶
WithCheck replaces the config-check behavior. The default accepts every config (nil error, no output). Use this to simulate haproxy rejecting a config: return output containing an "[ALERT]" line together with a non-nil error, mirroring a real `haproxy -c` failure.
func WithRejectAll ¶
WithRejectAll makes every config check fail the way `haproxy -c` fails on an invalid config: combined output carrying [ALERT] lines plus a non-nil exit error. alertDetail becomes the alert message, e.g. "parsing [haproxy.cfg:5] : unknown keyword 'invalid_directive'".
Tests using this simulate haproxy's verdict rather than reproduce it — coverage that the real binary actually rejects a given construct belongs in the integration suite.