mocks

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package mocks provides mocks and helpers used in testing.

Index

Constants

View Source
const (
	// TestDelay is the Retry-After delay used in tests.
	TestDelay = 0 * time.Second

	// TestHeader is the header used in tests.
	TestHeader = "x-test-header"

	// TestURL is the URL used in tests.
	TestURL = "https://microsoft.com/a/b/c/"
)

Variables

This section is empty.

Functions

func NewRequest

func NewRequest() *http.Request

NewRequest instantiates a new request.

func NewRequestForURL

func NewRequestForURL(u string) *http.Request

NewRequestForURL instantiates a new request using the passed URL.

func NewRequestWithContent

func NewRequestWithContent(c string) *http.Request

NewRequestWithContent instantiates a new request using the passed string for the body content.

func NewResponse

func NewResponse() *http.Response

NewResponse instantiates a new response.

func NewResponseWithContent

func NewResponseWithContent(c string) *http.Response

NewResponseWithContent instantiates a new response with the passed string as the body content.

func NewResponseWithStatus

func NewResponseWithStatus(s string, c int) *http.Response

NewResponseWithStatus instantiates a new response using the passed string and integer as the status and status code.

func SetAcceptedHeaders

func SetAcceptedHeaders(resp *http.Response)

SetAcceptedHeaders adds the headers usually associated with a 202 Accepted response.

func SetLocationHeader

func SetLocationHeader(resp *http.Response, location string)

SetLocationHeader adds the Location header.

func SetResponseHeader

func SetResponseHeader(resp *http.Response, h string, v string)

SetResponseHeader adds a header to the passed response.

func SetResponseHeaderValues

func SetResponseHeaderValues(resp *http.Response, h string, values []string)

SetResponseHeaderValues adds a header containing all the passed string values.

func SetRetryHeader

func SetRetryHeader(resp *http.Response, delay time.Duration)

SetRetryHeader adds the Retry-After header.

Types

type Body

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

Body implements acceptable body over a string.

func NewBody

func NewBody(s string) *Body

NewBody creates a new instance of Body.

func (*Body) Close

func (body *Body) Close() error

Close closes the body.

func (*Body) CloseAttempts

func (body *Body) CloseAttempts() int

CloseAttempts returns the number of times Close was called.

func (*Body) IsOpen

func (body *Body) IsOpen() bool

IsOpen returns true if the Body has not been closed, false otherwise.

func (*Body) Read

func (body *Body) Read(b []byte) (n int, err error)

Read reads into the passed byte slice and returns the bytes read.

type Sender

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

Sender implements a simple null sender.

func NewSender

func NewSender() *Sender

NewSender creates a new instance of Sender.

func (*Sender) Attempts

func (c *Sender) Attempts() int

Attempts returns the number of times Do was called.

func (*Sender) ClearError

func (c *Sender) ClearError()

ClearError clears the error Do emits.

func (*Sender) Do

func (c *Sender) Do(r *http.Request) (*http.Response, error)

Do accepts the passed request and, based on settings, emits a response and possible error.

func (*Sender) EmitContent

func (c *Sender) EmitContent(s string)

EmitContent sets the content to be returned by Do in the response body.

func (*Sender) EmitErrors

func (c *Sender) EmitErrors(emit int)

EmitErrors sets the number times Do should emit an error.

func (*Sender) EmitStatus

func (c *Sender) EmitStatus(status string, code int)

EmitStatus sets the status of the response Do emits.

func (*Sender) ReuseResponse

func (c *Sender) ReuseResponse(reuseResponse bool)

ReuseResponse sets if the just one response object should be reused by all calls to Do.

func (*Sender) SetError

func (c *Sender) SetError(err error)

SetError sets the error Do should return.

func (*Sender) SetPollAttempts

func (c *Sender) SetPollAttempts(pa int)

SetPollAttempts sets the number of times the returned response emits the default polling status code (i.e., 202 Accepted).

func (*Sender) SetResponse

func (c *Sender) SetResponse(resp *http.Response)

SetResponse sets the response from Do.

type T

type T struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}

T is a simple testing struct.

Jump to

Keyboard shortcuts

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