exported

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewResponse

func NewResponse(content ResponseContent, req *http.Request) (*http.Response, error)

NewResponse creates a new *http.Response with the specified content and req as the response's request.

func SanitizePagerPath

func SanitizePagerPath(path string) string

SanitizePagerPath removes any fake-appended suffix from a URL's path.

func SetResponseBody

func SetResponseBody(resp *http.Response, body []byte, contentType string) *http.Response

SetResponseBody wraps body in a nop-closing bytes reader and assigned it to resp.Body. The Content-Type header will be added with the specified value.

Types

type AddNonTerminalResponseOptions

type AddNonTerminalResponseOptions struct {
}

AddNonTerminalResponseOptions contains the optional values for PollerResponder[T].AddNonTerminalResponse.

type AddPageOptions

type AddPageOptions struct {
}

AddPageOptions contains the optional values for PagerResponder[T].AddPage.

type ErrorResponder

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

ErrorResponder represents a scalar error response.

func (ErrorResponder) GetError

func (e ErrorResponder) GetError(req *http.Request) error

GetError returns the error for this responder. This function is called by the fake server internals.

func (*ErrorResponder) SetError

func (e *ErrorResponder) SetError(err error)

SetError sets the specified error to be returned. Use SetResponseError for returning an *azcore.ResponseError.

func (*ErrorResponder) SetResponseError

func (e *ErrorResponder) SetResponseError(httpStatus int, errorCode string)

SetResponseError sets an *azcore.ResponseError with the specified values to be returned.

  • errorCode is the value to be used in the ResponseError.Code field
  • httpStatus is the HTTP status code

type PagerResponder

type PagerResponder[T any] struct {
	// contains filtered or unexported fields
}

PagerResponder represents a sequence of paged responses. Responses are replayed in the order in which they were added.

func (*PagerResponder[T]) AddError

func (p *PagerResponder[T]) AddError(err error)

AddError adds an error to the sequence of responses. The error is returned from the call to runtime.Pager[T].NextPage().

func (*PagerResponder[T]) AddPage

func (p *PagerResponder[T]) AddPage(httpStatus int, page T, o *AddPageOptions)

AddPage adds a page to the sequence of respones.

  • page is the response page to be added
  • o contains optional values, pass nil to accept the defaults

func (*PagerResponder[T]) AddResponseError

func (p *PagerResponder[T]) AddResponseError(httpStatus int, errorCode string)

AddResponseError adds an *azcore.ResponseError to the sequence of responses. The error is returned from the call to runtime.Pager[T].NextPage().

func (p *PagerResponder[T]) InjectNextLinks(req *http.Request, inject func(page *T, createLink func() string))

InjectNextLinks is used to populate the nextLink field. The inject callback is executed for every T in the sequence except for the last one. This function is called by the fake server internals.

func (*PagerResponder[T]) More

func (p *PagerResponder[T]) More() bool

More returns true if there are more responses for consumption. This function is called by the fake server internals.

func (*PagerResponder[T]) Next

func (p *PagerResponder[T]) Next(req *http.Request) (*http.Response, error)

Next returns the next response in the sequence (a T or an error). This function is called by the fake server internals.

type PollerResponder

type PollerResponder[T any] struct {
	// contains filtered or unexported fields
}

PollerResponder represents a sequence of responses for a long-running operation. Any non-terminal responses are replayed in the order in which they were added. The terminal response, success or error, is always the final response.

func (*PollerResponder[T]) AddNonTerminalResponse

func (p *PollerResponder[T]) AddNonTerminalResponse(httpStatus int, o *AddNonTerminalResponseOptions)

AddNonTerminalResponse adds a non-terminal response to the sequence of responses.

func (*PollerResponder[T]) AddPollingError

func (p *PollerResponder[T]) AddPollingError(err error)

AddPollingError adds an error to the sequence of responses. Use this to simulate an error durring polling. NOTE: adding this as the first response will cause the Begin* LRO API to return this error.

func (*PollerResponder[T]) More

func (p *PollerResponder[T]) More() bool

More returns true if there are more responses for consumption. This function is called by the fake server internals.

func (*PollerResponder[T]) Next

func (p *PollerResponder[T]) Next(req *http.Request) (*http.Response, error)

Next returns the next response in the sequence (a *http.Response or an error). This function is called by the fake server internals.

func (*PollerResponder[T]) SetTerminalError

func (p *PollerResponder[T]) SetTerminalError(httpStatus int, errorCode string)

SetTerminalError sets an *azcore.ResponseError with the specified values as the failed terminal response.

func (*PollerResponder[T]) SetTerminalResponse

func (p *PollerResponder[T]) SetTerminalResponse(httpStatus int, result T, o *SetTerminalResponseOptions)

SetTerminalResponse sets the provided value as the successful, terminal response.

type Responder

type Responder[T any] struct {
	// contains filtered or unexported fields
}

Responder represents a scalar response.

func (Responder[T]) GetResponse

func (r Responder[T]) GetResponse() T

GetResponse returns the response associated with the Responder. This function is called by the fake server internals.

func (Responder[T]) GetResponseContent

func (r Responder[T]) GetResponseContent() ResponseContent

GetResponseContent returns the ResponseContent associated with the Responder. This function is called by the fake server internals.

func (*Responder[T]) SetResponse

func (r *Responder[T]) SetResponse(httpStatus int, resp T, o *SetResponseOptions)

SetResponse sets the specified value to be returned.

  • httpStatus is the HTTP status code to be returned
  • resp is the response to be returned
  • o contains optional values, pass nil to accept the defaults

type ResponseContent

type ResponseContent struct {
	// HTTPStatus is the HTTP status code to use in the response.
	HTTPStatus int

	// Header contains the headers from SetResponseOptions.Header to include in the HTTP response.
	Header http.Header
}

ResponseContent is used when building the *http.Response. This type is used by the fake server internals.

type ResponseOptions

type ResponseOptions struct {
	// Body is the HTTP response body.
	Body io.ReadCloser

	// ContentType is the value for the Content-Type HTTP header.
	ContentType string
}

ResponseOptions contains the optional values for NewResponse().

type SetResponseOptions

type SetResponseOptions struct {
	// Header contains optional HTTP headers to include in the response.
	Header http.Header
}

SetResponseOptions contains the optional values for Responder[T].SetResponse.

type SetTerminalResponseOptions

type SetTerminalResponseOptions struct {
}

SetTerminalResponseOptions contains the optional values for PollerResponder[T].SetTerminalResponse.

Jump to

Keyboard shortcuts

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