testutil

package
v0.0.0-...-cd7ca46 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package testutil provides utilities for testing the HTTP protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurDir

func CurDir() (string, error)

CurDir returns the current directory of the caller.

func GetCertsPaths

func GetCertsPaths() (string, string, error)

GetCertsPaths returns the absolute paths to the certs located in the testdata directory, so they can be used in test throughout the project

func HTTPPythonServer

func HTTPPythonServer(t *testing.T, addr string, options Options) *exec.Cmd

HTTPPythonServer launches an HTTP python server.

func HTTPServer

func HTTPServer(t *testing.T, addr string, options Options) func()

HTTPServer spins up a HTTP test server that returns the status code included in the URL Example: * GET /200/foo returns a 200 status code; * PUT /404/bar returns a 404 status code; Optional TLS support using a self-signed certificate can be enabled trough the `enableTLS` argument nolint

func SetupNetIPV4TCPTimestamp

func SetupNetIPV4TCPTimestamp(t *testing.T, enable bool)

SetupNetIPV4TCPTimestamp sets the net.ipv4.tcp_timestamps to the provided value.

func StatusFromPath

func StatusFromPath(path string) uint16

StatusFromPath returns the status code present in the first segment of the request path

Types

type Options

type Options struct {
	// If TLS is enabled, allows to upgrade the connections to http/2.
	EnableHTTP2        bool
	EnableTLS          bool
	EnableKeepAlive    bool
	EnableTCPTimestamp *bool
	ReadTimeout        time.Duration
	WriteTimeout       time.Duration
	SlowResponse       time.Duration
}

Options wraps all configurable params for the HTTPServer

type TCPServer

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

TCPServer represents a basic TCP server configuration.

func NewTCPServer

func NewTCPServer(addr string, onMessage func(c net.Conn), isTLS bool) *TCPServer

NewTCPServer creates and initializes a new TCPServer instance with the provided address and callback function to handle incoming messages.

func (*TCPServer) Run

func (s *TCPServer) Run(done chan struct{}) error

Run starts the TCPServer to listen on its configured address.

Jump to

Keyboard shortcuts

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