package mock

import "github.com/Azure/azure-sdk-for-go/sdk/internal/mock"

Index

Types

type ResponseOption

type ResponseOption interface {
	// contains filtered or unexported methods
}

ResponseOption is an abstraction for configuring a mock HTTP response.

func WithBody

func WithBody(b []byte) ResponseOption

WithBody sets the HTTP response's body to the specified value.

func WithBodyReadError

func WithBodyReadError() ResponseOption

WithBodyReadError returns a response that will fail when reading the body.

func WithHeader

func WithHeader(k, v string) ResponseOption

WithHeader adds the specified header and value to the HTTP response.

func WithSlowResponse

func WithSlowResponse(d time.Duration) ResponseOption

WithSlowResponse will sleep for the specified duration before returning the HTTP response.

func WithStatusCode

func WithStatusCode(c int) ResponseOption

WithStatusCode sets the HTTP response's status code to the specified value.

type Server

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

Server is a wrapper around an httptest.Server. The serving of requests is not safe for concurrent use which is ok for right now as each test creates is own server and doesn't create additional go routines.

func NewServer

func NewServer() (*Server, func())

NewServer creates a new Server object. The returned close func must be called when the server is no longer needed.

func NewTLSServer

func NewTLSServer() (*Server, func())

NewTLSServer creates a new Server object. The returned close func must be called when the server is no longer needed.

func (*Server) AppendError

func (s *Server) AppendError(err error)

AppendError appends the error to the end of the response queue.

func (*Server) AppendResponse

func (s *Server) AppendResponse(opts ...ResponseOption)

AppendResponse appends the response to the end of the response queue. If no options are provided the default response is an http.StatusOK.

func (*Server) Do

func (s *Server) Do(ctx context.Context, req *http.Request) (*http.Response, error)

Do implements the azcore.Transport interface on Server. Calling this when the response queue is empty and no static response has been set will cause a panic.

func (*Server) RepeatError

func (s *Server) RepeatError(n int, err error)

RepeatError appends the error n number of times to the end of the response queue.

func (*Server) RepeatResponse

func (s *Server) RepeatResponse(n int, opts ...ResponseOption)

RepeatResponse appends the response n number of times to the end of the response queue. If no options are provided the default response is an http.StatusOK.

func (*Server) Requests

func (s *Server) Requests() int

Requests returns the number of times an HTTP request was made.

func (*Server) SetError

func (s *Server) SetError(err error)

SetError indicates the same error should always be returned. Any responses set via other methods will be ignored.

func (*Server) SetResponse

func (s *Server) SetResponse(opts ...ResponseOption)

SetResponse indicates the same response should always be returned. Any responses set via other methods will be ignored. If no options are provided the default response is an http.StatusOK.

func (*Server) URL

func (s *Server) URL() url.URL

URL returns the endpoint of the test server in URL format.

Source Files

mock.go

Version
v0.2.2
Published
Jul 23, 2020
Platform
js/wasm
Imports
8 packages
Last checked
55 minutes ago

Tools for package owners.