testutil

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2015 License: Apache-2.0, Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateRandomTarFile

func CreateRandomTarFile() (rs io.ReadSeeker, tarSum string, err error)

CreateRandomTarFile creates a random tarfile, returning it as an io.ReadSeeker along with its tarsum. An error is returned if there is a problem generating valid content.

func NewHandler

func NewHandler(requestResponseMap RequestResponseMap) http.Handler

NewHandler returns a new test handler that responds to defined requests with specified responses Each time a Request is received, the next Response is returned in the mapping, until no Responses are defined, at which point a 404 is sent back

Types

type Request

type Request struct {
	// Method is the http method of the request, for example GET
	Method string

	// Route is the http route of this request
	Route string

	// QueryParams are the query parameters of this request
	QueryParams map[string][]string

	// Body is the byte contents of the http request
	Body []byte

	// Headers are the header for this request
	Headers http.Header
}

Request is a simplified http.Request object

func (Request) String

func (r Request) String() string

type RequestResponseMap

type RequestResponseMap []RequestResponseMapping

RequestResponseMap is an ordered mapping from Requests to Responses

type RequestResponseMapping

type RequestResponseMapping struct {
	Request  Request
	Response Response
}

RequestResponseMapping defines a Response to be sent in response to a given Request

type Response

type Response struct {
	// Statuscode is the http status code of the Response
	StatusCode int

	// Headers are the http headers of this Response
	Headers http.Header

	// Body is the response body
	Body []byte
}

Response is a simplified http.Response object

Jump to

Keyboard shortcuts

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