harness

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package harness launches a real haproxy subprocess with route.lua loaded for integration tests. Each test directory ships a real haproxy.cfg and any map fixtures it needs; the harness copies them into a tempdir, fills in runtime placeholders, and exposes HTTP / runtime-socket helpers.

Placeholders substituted in the cfg:

{{HTTP_SOCK}}   unix socket the frontend should bind to
{{ADMIN_SOCK}}  runtime API socket path
{{ROUTE_LUA}}   absolute path to fs/usr/local/hug/route.lua
{{DIR}}         tempdir where this test's fixtures live (maps, etc.)

Tests skip if the haproxy binary is missing or older than 3.1 (route.lua relies on core.get_patref iteration, which is reliable from 3.1+).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Harness

type Harness struct {
	Dir       string // tempdir where copied fixtures live
	HTTPSock  string // unix socket for HTTP requests
	AdminSock string // unix socket for runtime API
	// contains filtered or unexported fields
}

Harness wraps a running haproxy instance.

func New

func New(t *testing.T, cfgPath string) *Harness

New starts haproxy using the cfg file at cfgPath (relative to the test's working directory, which is the test file's package directory). Every non-.go sibling file under the cfg's directory is copied into a tempdir before haproxy starts, so map files etc. can live next to the cfg.

func (*Harness) Get

func (h *Harness) Get(t *testing.T, urlPath string, hdrs ...string) (status int, body string)

Get sends a GET request. hdrs are alternating key/value pairs; "Host" is handled specially (Go's Header.Set("Host",…) is silently ignored).

func (*Harness) Log

func (h *Harness) Log() string

Log returns the haproxy stdout/stderr captured so far.

func (*Harness) Socket

func (h *Harness) Socket(t *testing.T, cmd string) string

Socket sends a command to the runtime API socket and returns the response.

Jump to

Keyboard shortcuts

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