testserver

package
v0.0.0-...-66219d0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CapturedRequest

type CapturedRequest struct {
	Method  string
	Path    string
	Headers http.Header
	Body    string
}

CapturedRequest holds information about a received request

type HandlerConfig

type HandlerConfig struct {
	StatusCode int
	Headers    map[string]string
	Body       string
	Delay      time.Duration
}

HandlerConfig allows configuring the server's response

type TestServer

type TestServer struct {
	Server   *http.Server
	Listener net.Listener
	URL      string
	Requests []*CapturedRequest
	// contains filtered or unexported fields
}

TestServer represents a configurable HTTP/HTTPS test server

func New

func New() (*TestServer, error)

New creates a new HTTP test server

func NewTLS

func NewTLS() (*TestServer, error)

NewTLS creates a new HTTPS test server with self-signed certificate

func NewTLSWithConfig

func NewTLSWithConfig(config *HandlerConfig) (*TestServer, error)

NewTLSWithConfig creates a new HTTPS test server with custom response config

func NewWithConfig

func NewWithConfig(config *HandlerConfig) (*TestServer, error)

NewWithConfig creates a new HTTP test server with custom response config

func (*TestServer) ClearRequests

func (ts *TestServer) ClearRequests()

ClearRequests clears all captured requests (thread-safe)

func (*TestServer) Close

func (ts *TestServer) Close() error

Close shuts down the test server

func (*TestServer) GetRequests

func (ts *TestServer) GetRequests() []*CapturedRequest

GetRequests returns all captured requests (thread-safe)

Jump to

Keyboard shortcuts

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