go-autorest: github.com/Azure/go-autorest/autorest/mocks Index | Files

package mocks

import "github.com/Azure/go-autorest/autorest/mocks"

Package mocks provides mocks and helpers used in testing.

Index

Package Files

helpers.go mocks.go

Constants

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

func NewRequest Uses

func NewRequest() *http.Request

NewRequest instantiates a new request.

func NewRequestForURL Uses

func NewRequestForURL(u string) *http.Request

NewRequestForURL instantiates a new request using the passed URL.

func NewRequestWithCloseBody Uses

func NewRequestWithCloseBody() *http.Request

NewRequestWithCloseBody instantiates a new request.

func NewRequestWithCloseBodyContent Uses

func NewRequestWithCloseBodyContent(c string) *http.Request

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

func NewRequestWithContent Uses

func NewRequestWithContent(c string) *http.Request

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

func NewRequestWithParams Uses

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

NewRequestWithParams instantiates a new request using the provided parameters.

func NewResponse Uses

func NewResponse() *http.Response

NewResponse instantiates a new response.

func NewResponseWithBodyAndStatus Uses

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 NewResponseWithBytes Uses

func NewResponseWithBytes(input []byte) *http.Response

NewResponseWithBytes instantiates a new response with the passed bytes as the body content.

func NewResponseWithContent Uses

func NewResponseWithContent(c string) *http.Response

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

func NewResponseWithStatus Uses

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 Uses

func SetAcceptedHeaders(resp *http.Response)

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

func SetLocationHeader Uses

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

SetLocationHeader adds the Location header.

func SetResponseHeader Uses

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

SetResponseHeader adds a header to the passed response.

func SetResponseHeaderValues Uses

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

SetResponseHeaderValues adds a header containing all the passed string values.

func SetRetryHeader Uses

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

SetRetryHeader adds the Retry-After header.

type Body Uses

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

Body implements acceptable body over a string.

func NewBody Uses

func NewBody(s string) *Body

NewBody creates a new instance of Body.

func NewBodyClose Uses

func NewBodyClose(s string) *Body

NewBodyClose creates a new instance of Body.

func NewBodyWithBytes Uses

func NewBodyWithBytes(b []byte) *Body

NewBodyWithBytes creates a new instance of Body.

func (*Body) Close Uses

func (body *Body) Close() error

Close closes the body.

func (*Body) CloseAttempts Uses

func (body *Body) CloseAttempts() int

CloseAttempts returns the number of times Close was called.

func (*Body) IsOpen Uses

func (body *Body) IsOpen() bool

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

func (*Body) Length Uses

func (body *Body) Length() int64

Length returns the number of bytes in the body.

func (*Body) Read Uses

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

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

type Sender Uses

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

Sender implements a simple null sender.

func NewSender Uses

func NewSender() *Sender

NewSender creates a new instance of Sender.

func (*Sender) AppendAndRepeatError Uses

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 Uses

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 Uses

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 Uses

func (c *Sender) AppendError(err error)

AppendError adds the passed error to the response stack.

func (*Sender) AppendResponse Uses

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

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

func (*Sender) AppendResponseWithDelay Uses

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 Uses

func (c *Sender) Attempts() int

Attempts returns the number of times Do was called.

func (*Sender) Do Uses

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 Uses

func (c *Sender) NumResponses() int

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

func (*Sender) SetAndRepeatError Uses

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 Uses

func (c *Sender) SetEmitErrorAfter(ea int)

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

func (*Sender) SetError Uses

func (c *Sender) SetError(err error)

SetError sets the error Do should return.

type T Uses

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

T is a simple testing struct.

Package mocks imports 4 packages (graph) and is imported by 1 packages. Updated 2019-07-01. Refresh now. Tools for package owners.