azuretesting

package
v0.0.0-...-ea3e8b0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRequest

func NewRequest() *http.Request

NewRequest instantiates a new request.

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 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 SetResponseHeaderValues

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

SetResponseHeaderValues adds a header containing all the passed string values.

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

type FakeCredential struct{}

FakeCredential is a credential that returns a fake token.

func (*FakeCredential) GetToken

type MockSender

type MockSender struct {

	// PathPattern, if non-empty, is assumed to be a regular expression
	// that must match the request path.
	PathPattern string
	// contains filtered or unexported fields
}

MockSender provides a mechanism to test requests and provide responses to/from the Azure cloud API.

func NewSenderWithValue

func NewSenderWithValue(v interface{}) *MockSender

NewSenderWithValue returns a *mocks.Sender that marshals the provided object to JSON and sets it as the content. This function will panic if marshalling fails.

func (*MockSender) AppendAndRepeatResponse

func (c *MockSender) 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 (*MockSender) AppendResponse

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

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

func (*MockSender) Attempts

func (c *MockSender) Attempts() int

Attempts returns the number of times Do was called.

func (*MockSender) Do

func (s *MockSender) Do(req *http.Request) (resp *http.Response, err error)

Do implements policy.Policy.

func (*MockSender) NumResponses

func (c *MockSender) NumResponses() int

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

func (*MockSender) SetAndRepeatError

func (c *MockSender) 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 (*MockSender) SetError

func (c *MockSender) SetError(err error)

SetError sets the error Do should return.

type RequestRecorderPolicy

type RequestRecorderPolicy struct {
	Requests *[]*http.Request
	// contains filtered or unexported fields
}

func (*RequestRecorderPolicy) Do

type Senders

type Senders []policy.Transporter

Senders is a Sender that includes a collection of Senders, which will be called in sequence.

func (*Senders) Do

func (s *Senders) Do(req *http.Request) (*http.Response, error)

type SerialSender

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

SerialSender is a Sender that permits only one active Do call at a time.

func NewSerialSender

func NewSerialSender(s policy.Transporter) *SerialSender

func (*SerialSender) Do

func (s *SerialSender) Do(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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