htttest

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 11 Imported by: 0

README

htttest

Opinionated go package for rapid testing of real HTTP APIs integrations. Zero deps.

Usage

Documentation

Overview

Package htttest is built for rapid testing of real HTTP APIs integrations.

Example

Index

Examples

Constants

View Source
const RecordModeEnv = "HTTTEST_RECORD_MODE"

Variables

This section is empty.

Functions

func NewDefaultTestClient

func NewDefaultTestClient(t *testing.T, opts ...Option) *http.Client

NewDefaultTestClient returns a new http.Client that will either dump requests to the given dir or read them from it. It can be used to record and replay http requests.

Types

type NamingScheme

type NamingScheme interface {
	FileNames(RequestMeta) (reqFile, respFile string)
}

type Option

type Option func(*config)

func WithDumpMode

func WithDumpMode() Option

WithDumpMode allows user to set the record mode explicitly to chosen value. You might prefer to use this option instead of setting the environment variable.

func WithNamingScheme

func WithNamingScheme(n NamingScheme) Option

WithNamingScheme allows user to set the naming scheme for the recorded requests. By default, the naming scheme is set to SequentialNamingScheme.

func WithParentHTTPClient

func WithParentHTTPClient(c *http.Client) Option

WithParentHTTPClient allows user to set the parent http client.

type RequestMeta

type RequestMeta struct{}

RequestMeta is some data related to the request, that can be used to create filename in the naming scheme

type RequestSanitizer

type RequestSanitizer interface {
	SanitizeRequest(req *http.Request) *http.Request
}

RequestSanitizer ensures, that no sensitive data is written to the request records. The sanitized version would be stored, whilst the original one would be sent in the record mode. It is allowed to mutate the request in place, becuase it is copied before invoking the RoundTrip method.

func ComposedRequestSanitizer

func ComposedRequestSanitizer(s ...RequestSanitizer) RequestSanitizer

func DefaultHeadersSanitizer

func DefaultHeadersSanitizer() RequestSanitizer

func DefaultQueryParamsSanitizer

func DefaultQueryParamsSanitizer() RequestSanitizer

func DefaultRequestSanitizer

func DefaultRequestSanitizer() RequestSanitizer

DefaultRequestSanitizer returns a RequestSanitizer that sanitizes headers and query parameters.

func HeadersSanitizer

func HeadersSanitizer(headers ...string) RequestSanitizer

func QueryParamsSanitizer

func QueryParamsSanitizer(params ...string) RequestSanitizer

type RequestSanitizerFunc

type RequestSanitizerFunc func(req *http.Request) *http.Request

func (RequestSanitizerFunc) SanitizeRequest

func (f RequestSanitizerFunc) SanitizeRequest(req *http.Request) *http.Request

type SequentialNamingScheme

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

func NewSequentialNamingScheme

func NewSequentialNamingScheme(dir string) (*SequentialNamingScheme, error)

func (*SequentialNamingScheme) FileNames

func (s *SequentialNamingScheme) FileNames(_ RequestMeta) (reqFile, respFile string)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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