httpmock

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MIT Imports: 2 Imported by: 0

README

Httpmock

Package httpmock provides boilerplate code necessary for testing functions using http.Client by the Transport method.

Install

go get -u github.com/sean-rn/httpmock

Usage

func NewHandlerClient
func NewHandlerClient(handler http.HandlerFunc) *http.Client

NewHandlerClient returns *http.Client with Transport replaced with one that only invokes handler to avoid making real calls.

func NewTransportClient
func NewTransportClient(fn RoundTripperFunc) *http.Client

NewTransportClient is a convenience function that returns *http.Client with Transport replaced to avoid making real calls

type RoundTripperFunc
type RoundTripperFunc func(req *http.Request) (*http.Response, error)

The RoundTripperFunc type is an adapter to allow the use of ordinary functions as HTTP Client transports. If f is a function with the appropriate signature, RoundTripperFunc(f) is a RoundTripper that calls f. This really ought to already be in the net/http/httptest package, it's just like http.HandlerFunc

func HandlerTransport
func HandlerTransport(handler http.HandlerFunc) RoundTripperFunc

HandlerTransport returns a new RoundTripFunc that invokes handler and returns the response it wrote.

func (RoundTripperFunc) RoundTrip
func (f RoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip makes RoundTripFunc implement http.RoundTripper. It calls f(req)

Documentation

Overview

Package httpmock provides boilerplate code necessary for testing functions using http.Client by the Transport method.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandlerClient

func NewHandlerClient(handler http.HandlerFunc) *http.Client

NewHandlerClient returns *http.Client with Transport replaced with one that only invokes handler to avoid making real calls.

func NewTransportClient

func NewTransportClient(fn RoundTripperFunc) *http.Client

NewTransportClient is a convenience function that returns *http.Client with Transport replaced to avoid making real calls

Types

type RoundTripperFunc

type RoundTripperFunc func(req *http.Request) (*http.Response, error)

The RoundTripperFunc type is an adapter to allow the use of ordinary functions as HTTP Client transports. If f is a function with the appropriate signature, RoundTripperFunc(f) is a RoundTripper that calls f. This really ought to already be in the net/http/httptest package, it's just like http.HandlerFunc

func HandlerTransport

func HandlerTransport(handler http.HandlerFunc) RoundTripperFunc

HandlerTransport returns a new RoundTripFunc that invokes `handler` and returns the response it wrote.

func (RoundTripperFunc) RoundTrip

func (f RoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip makes RoundTripFunc implement http.RoundTripper. It calls f(req)

Jump to

Keyboard shortcuts

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