Documentation
¶
Overview ¶
Package htttest is built for rapid testing of real HTTP APIs integrations.
Example ¶
Index ¶
- Constants
- func NewDefaultTestClient(t *testing.T, opts ...Option) *http.Client
- type NamingScheme
- type Option
- type RequestMeta
- type RequestSanitizer
- func ComposedRequestSanitizer(s ...RequestSanitizer) RequestSanitizer
- func DefaultHeadersSanitizer() RequestSanitizer
- func DefaultQueryParamsSanitizer() RequestSanitizer
- func DefaultRequestSanitizer() RequestSanitizer
- func HeadersSanitizer(headers ...string) RequestSanitizer
- func QueryParamsSanitizer(params ...string) RequestSanitizer
- type RequestSanitizerFunc
- type SequentialNamingScheme
Examples ¶
Constants ¶
const RecordModeEnv = "HTTTEST_RECORD_MODE"
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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 ¶
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)