http

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package http provides functionalities for mocking net/http components.

Index

Constants

View Source
const (
	// MethodGet is an alias of http.MethodGet.
	MethodGet = http.MethodGet
	// MethodPost is an alias of http.MethodPost.
	MethodPost = http.MethodPost

	// StatusOK is an alias of http.StatusOK.
	StatusOK = http.StatusOK
	// StatusCreated is an lias of http.StatusCreated.
	StatusCreated = http.StatusCreated
)

Variables

View Source
var NoMockResponseWriter = MockResponseWriter()

NoMockResponseWriter is no mock ResponseWriter.

Functions

This section is empty.

Types

type Header = http.Header

Header is an alias of http.Header.

type Request

type Request = http.Request

Request is an alias of http.Request.

type RequestBuilder added in v0.10.0

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

RequestBuilder is a builder that constructs a http request.

func BuildRequest

func BuildRequest() *RequestBuilder

BuildRequest builds a Request. nolint: revive

func (*RequestBuilder) Build added in v0.10.0

func (b *RequestBuilder) Build() *http.Request

Build returns the request.

func (*RequestBuilder) WithBody added in v0.10.0

func (b *RequestBuilder) WithBody(body string) *RequestBuilder

WithBody sets the request body.

func (*RequestBuilder) WithBodyCloseError added in v0.10.0

func (b *RequestBuilder) WithBodyCloseError(err error) *RequestBuilder

WithBodyCloseError sets the request body that returns an error while closing.

func (*RequestBuilder) WithBodyReadError added in v0.10.0

func (b *RequestBuilder) WithBodyReadError(err error) *RequestBuilder

WithBodyReadError sets the request body that returns an error while reading.

func (*RequestBuilder) WithHeader added in v0.10.0

func (b *RequestBuilder) WithHeader(key, value string) *RequestBuilder

WithHeader sets the request header.

func (*RequestBuilder) WithMethod added in v0.10.0

func (b *RequestBuilder) WithMethod(method string) *RequestBuilder

WithMethod sets the http method.

func (*RequestBuilder) WithURI added in v0.10.0

func (b *RequestBuilder) WithURI(uri string) *RequestBuilder

WithURI sets the request uri.

type ResponseWriter

type ResponseWriter struct {
	mock.Mock
}

ResponseWriter is a http.ResponseWriter.

func (*ResponseWriter) Header

func (r *ResponseWriter) Header() http.Header

Header satisfies http.ResponseWriter interface.

func (*ResponseWriter) Write

func (r *ResponseWriter) Write(bytes []byte) (int, error)

Write satisfies http.ResponseWriter interface.

func (*ResponseWriter) WriteHeader

func (r *ResponseWriter) WriteHeader(statusCode int)

WriteHeader satisfies http.ResponseWriter interface.

type ResponseWriterMocker

type ResponseWriterMocker func(tb testing.TB) *ResponseWriter

ResponseWriterMocker is ResponseWriter mocker.

func MockResponseWriter

func MockResponseWriter(mocks ...func(w *ResponseWriter)) ResponseWriterMocker

MockResponseWriter creates ResponseWriter mock with cleanup to ensure all the expectations are met.

Jump to

Keyboard shortcuts

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