testutil

package
v0.2.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package testutil provides a fixture unix-socket server for exercising the pluggablevalidator client without spinning up a real haproxy-spoa-hub sidecar. Tests script the canned response per request and inspect what the client wrote.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FixtureServer

type FixtureServer struct {
	SocketPath string
	// contains filtered or unexported fields
}

FixtureServer is a single-connection-per-request unix-socket server that replays a canned response for every accepted connection. Mirrors the hub-side behaviour from haproxy-spoa-hub specs/004-validate-mode.

Use NewFixtureServer to start one at a tempdir-scoped socket path. Stop is idempotent and called automatically via t.Cleanup.

func NewFixtureServer

func NewFixtureServer(t *testing.T) *FixtureServer

NewFixtureServer starts a fixture server on a tempdir-scoped socket. The caller MUST call SetResponse before any client connects, or the server will close the connection without responding.

func (*FixtureServer) Requests

func (s *FixtureServer) Requests() [][]byte

Requests returns a copy of the bodies received so far, in the order the connections were accepted.

func (*FixtureServer) SetRawResponse

func (s *FixtureServer) SetRawResponse(frame []byte)

SetRawResponse records a fully-formed wire frame (length prefix included) to send back. Use to inject malformed responses or oversized frames.

func (*FixtureServer) SetResponse

func (s *FixtureServer) SetResponse(v any) error

SetResponse records the JSON value the server will encode (length-prefixed) onto every subsequent connection. Pass nil to make the server close the connection without writing anything (simulates a server crash mid-request).

func (*FixtureServer) SetResponseDelay

func (s *FixtureServer) SetResponseDelay(d time.Duration)

SetResponseDelay makes the server wait the given duration before writing the response. Use to test client-side timeouts.

func (*FixtureServer) Stop

func (s *FixtureServer) Stop()

Stop closes the listener and waits for the accept goroutine to exit. Safe to call more than once.

Jump to

Keyboard shortcuts

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