httptest

package
v3.24.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Anything is used where the expectation should not be considered.
	Anything = "httpx/httptest.Anything"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Expectation

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

Expectation represents an http request expectation.

func (*Expectation) Handle

func (e *Expectation) Handle(fn http.HandlerFunc)

Handle sets the HTTP handler function to be run on the request.

func (*Expectation) Header

func (e *Expectation) Header(k, v string) *Expectation

Header sets the HTTP headers that should be returned.

func (*Expectation) Returns

func (e *Expectation) Returns(status int, body []byte)

Returns sets the HTTP stats and body bytes to return.

func (*Expectation) ReturnsStatus

func (e *Expectation) ReturnsStatus(status int)

ReturnsStatus sets the HTTP stats code to return.

func (*Expectation) ReturnsString

func (e *Expectation) ReturnsString(status int, body string)

ReturnsString sets the HTTP stats and body string to return.

func (*Expectation) Times

func (e *Expectation) Times(times int) *Expectation

Times sets the number of times the request can be made.

type Server

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

Server represents a mock http server.

func NewServer

func NewServer(t *testing.T) *Server

NewServer creates a new mock http server.

func (*Server) AssertExpectations

func (s *Server) AssertExpectations()

AssertExpectations asserts all expectations have been met.

func (*Server) Close

func (s *Server) Close()

Close closes the server.

func (*Server) On

func (s *Server) On(method, path string) *Expectation

On creates an expectation of a request on the server.

func (*Server) URL

func (s *Server) URL() string

URL returns the url of the mock server.

Jump to

Keyboard shortcuts

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