mocks

package
v12.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2019 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 (
	// TestAuthorizationHeader is a faux HTTP Authorization header value
	TestAuthorizationHeader = "BEARER SECRETTOKEN"

	// TestBadURL is a malformed URL
	TestBadURL = "                               "

	// 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/"

	// TestAzureAsyncURL is a URL used in Azure asynchronous tests
	TestAzureAsyncURL = "https://microsoft.com/a/b/c/async"

	// TestLocationURL is a URL used in Azure asynchronous tests
	TestLocationURL = "https://microsoft.com/a/b/c/location"
)

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 NewRequestWithCloseBody

func NewRequestWithCloseBody() *http.Request

NewRequestWithCloseBody instantiates a new request.

func NewRequestWithCloseBodyContent

func NewRequestWithCloseBodyContent(c string) *http.Request

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

func NewRequestWithContent

func NewRequestWithContent(c string) *http.Request

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

func NewRequestWithParams

func NewRequestWithParams(method, u string, body io.Reader) *http.Request

NewRequestWithParams instantiates a new request using the provided parameters.

func NewResponse

func NewResponse() *http.Response

NewResponse instantiates a new response.

func NewResponseWithBodyAndStatus

func NewResponseWithBodyAndStatus(body *Body, c int, s string) *http.Response

NewResponseWithBodyAndStatus instantiates a new response using the specified mock body, status and status code

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 NewBodyClose

func NewBodyClose(s string) *Body

NewBodyClose 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) Length

func (body *Body) Length() int64

Length returns the number of bytes in the body.

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) AppendAndRepeatError

func (c *Sender) AppendAndRepeatError(err error, repeat int)

AppendAndRepeatError adds the passed error to the response stack along with a repeat count. A negative repeat count will return the response for all remaining calls to Do.

func (*Sender) AppendAndRepeatResponse

func (c *Sender) AppendAndRepeatResponse(resp *http.Response, repeat int)

AppendAndRepeatResponse adds the passed http.Response to the response stack along with a repeat count. A negative repeat count will return the response for all remaining calls to Do.

func (*Sender) AppendAndRepeatResponseWithDelay

func (c *Sender) AppendAndRepeatResponseWithDelay(resp *http.Response, delay time.Duration, repeat int)

AppendAndRepeatResponseWithDelay adds the passed http.Response to the response stack with the specified delay along with a repeat count. A negative repeat count will return the response for all remaining calls to Do.

func (*Sender) AppendError

func (c *Sender) AppendError(err error)

AppendError adds the passed error to the response stack.

func (*Sender) AppendResponse

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

AppendResponse adds the passed http.Response to the response stack.

func (*Sender) AppendResponseWithDelay

func (c *Sender) AppendResponseWithDelay(resp *http.Response, delay time.Duration)

AppendResponseWithDelay adds the passed http.Response to the response stack with the specified delay.

func (*Sender) Attempts

func (c *Sender) Attempts() int

Attempts returns the number of times Do was called.

func (*Sender) Do

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

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

func (*Sender) NumResponses

func (c *Sender) NumResponses() int

NumResponses returns the number of responses that have been added to the sender.

func (*Sender) SetAndRepeatError

func (c *Sender) SetAndRepeatError(err error, repeat int)

SetAndRepeatError sets the error Do should return and how many calls to Do will return the error. A negative repeat value will return the error for all remaining calls to Do.

func (*Sender) SetEmitErrorAfter

func (c *Sender) SetEmitErrorAfter(ea int)

SetEmitErrorAfter sets the number of attempts to be made before errors are emitted.

func (*Sender) SetError

func (c *Sender) SetError(err error)

SetError sets the error Do should return.

type T

type T struct {
	Name string `json:"name" xml:"Name"`
	Age  int    `json:"age" xml:"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