package mock
import "github.com/Azure/azure-sdk-for-go/sdk/internal/mock"
Index ¶
- type ResponseOption
- func WithBody(b []byte) ResponseOption
- func WithBodyReadError() ResponseOption
- func WithHeader(k, v string) ResponseOption
- func WithSlowResponse(d time.Duration) ResponseOption
- func WithStatusCode(c int) ResponseOption
- type Server
- func NewServer() (*Server, func())
- func NewTLSServer() (*Server, func())
- func (s *Server) AppendError(err error)
- func (s *Server) AppendResponse(opts ...ResponseOption)
- func (s *Server) Do(ctx context.Context, req *http.Request) (*http.Response, error)
- func (s *Server) RepeatError(n int, err error)
- func (s *Server) RepeatResponse(n int, opts ...ResponseOption)
- func (s *Server) Requests() int
- func (s *Server) SetError(err error)
- func (s *Server) SetResponse(opts ...ResponseOption)
- func (s *Server) URL() url.URL
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 ¶
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 ¶
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 ¶
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 ¶
Requests returns the number of times an HTTP request was made.
func (*Server) SetError ¶
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 ¶
URL returns the endpoint of the test server in URL format.
Source Files ¶
- Version
- v0.1.1
- Published
- Jun 29, 2020
- Platform
- darwin/amd64
- Imports
- 7 packages
- Last checked
- now –
Tools for package owners.