Documentation ¶
Index ¶
- func BodyAsJson(t *testing.T, resp *http.Response, jsonBody any)
- func BodyAsString(t *testing.T, resp *http.Response) string
- type HttpTestRunner
- func (r *HttpTestRunner) Clear() *HttpTestRunner
- func (r *HttpTestRunner) ClearBodyAfter() *HttpTestRunner
- func (r *HttpTestRunner) ClearFuncAfter() *HttpTestRunner
- func (r *HttpTestRunner) ClearHeaderAfter() *HttpTestRunner
- func (r *HttpTestRunner) Delete() (resp *http.Response, err error)
- func (r *HttpTestRunner) Get() (resp *http.Response, err error)
- func (r *HttpTestRunner) Head() (resp *http.Response, err error)
- func (r *HttpTestRunner) Post() (resp *http.Response, err error)
- func (r *HttpTestRunner) Put() (resp *http.Response, err error)
- func (r *HttpTestRunner) Run() (resp *http.Response, err error)
- func (r *HttpTestRunner) WithBody(body io.Reader) *HttpTestRunner
- func (r *HttpTestRunner) WithFunc(hFunc func(http.ResponseWriter, *http.Request)) *HttpTestRunner
- func (r *HttpTestRunner) WithHandler(handler http.Handler) *HttpTestRunner
- func (r *HttpTestRunner) WithHeader(key string, value string) *HttpTestRunner
- func (r *HttpTestRunner) WithJsonBody(typedBody any) *HttpTestRunner
- func (r *HttpTestRunner) WithMethod(method string) *HttpTestRunner
- func (r *HttpTestRunner) WithPath(path string) *HttpTestRunner
- func (r *HttpTestRunner) WithStringBody(stringBody string) *HttpTestRunner
- func (r *HttpTestRunner) WithValues(values url.Values) *HttpTestRunner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BodyAsJson ¶
BodyAsJson unmarshal the body of a request to json
Types ¶
type HttpTestRunner ¶
type HttpTestRunner struct {
// contains filtered or unexported fields
}
func NewHttpTestRunner ¶
func NewHttpTestRunner(t *testing.T) *HttpTestRunner
NewHttpTestRunner create a new runner with empty headers, method as http.MethodGet and root path as default.
func (*HttpTestRunner) Clear ¶
func (r *HttpTestRunner) Clear() *HttpTestRunner
Clear set body and hFunc as nil, and empty the header. Also clearBody, clearHFunc, and clearHeader flags are set to false.
func (*HttpTestRunner) ClearBodyAfter ¶
func (r *HttpTestRunner) ClearBodyAfter() *HttpTestRunner
ClearBodyAfter set body to be cleared after HttpTestRunner.Run execution
func (*HttpTestRunner) ClearFuncAfter ¶
func (r *HttpTestRunner) ClearFuncAfter() *HttpTestRunner
ClearBodyAfter set hFunc to be cleared after HttpTestRunner.Run execution
func (*HttpTestRunner) ClearHeaderAfter ¶
func (r *HttpTestRunner) ClearHeaderAfter() *HttpTestRunner
ClearHeaderAfter set the header to be cleared after HttpTestRunner.Run execution
func (*HttpTestRunner) Delete ¶
func (r *HttpTestRunner) Delete() (resp *http.Response, err error)
Delete set method to http.Delete, call HttpTestRunner.Run, and reset method to the previous if it is the case.
func (*HttpTestRunner) Get ¶
func (r *HttpTestRunner) Get() (resp *http.Response, err error)
Get set method to http.Get, call HttpTestRunner.Run, and reset method to the previous if it is the case.
func (*HttpTestRunner) Head ¶
func (r *HttpTestRunner) Head() (resp *http.Response, err error)
Head set method to http.Head, call HttpTestRunner.Run, and reset method to the previous if it is the case.
func (*HttpTestRunner) Post ¶
func (r *HttpTestRunner) Post() (resp *http.Response, err error)
Post set method to http.Post, call HttpTestRunner.Run, and reset method to the previous if it is the case.
func (*HttpTestRunner) Put ¶
func (r *HttpTestRunner) Put() (resp *http.Response, err error)
Put set method to http.Put, call HttpTestRunner.Run, and reset method to the previous if it is the case.
func (*HttpTestRunner) Run ¶
func (r *HttpTestRunner) Run() (resp *http.Response, err error)
Run the http method if it is allowed
func (*HttpTestRunner) WithBody ¶
func (r *HttpTestRunner) WithBody(body io.Reader) *HttpTestRunner
WithBody set HttpTestRunner.body using an io.Reader
func (*HttpTestRunner) WithFunc ¶
func (r *HttpTestRunner) WithFunc( hFunc func(http.ResponseWriter, *http.Request)) *HttpTestRunner
WithFunc set a function to be exectued by the runner.
If a function is defined, it will bypass the handler.
Use ClearFuncAfter to run the function once and clear it for the next HttpTestRunner.Run execution.
func (*HttpTestRunner) WithHandler ¶
func (r *HttpTestRunner) WithHandler(handler http.Handler) *HttpTestRunner
WithHandler set a handler to be executed by the runner.
If a function is defined, it will bypass this handler.
Use ClearFuncAfter to run the function once and clear it for the next HttpTestRunner.Run execution.
func (*HttpTestRunner) WithHeader ¶
func (r *HttpTestRunner) WithHeader(key string, value string) *HttpTestRunner
WithHeader add a key/value pair to be added to the header
func (*HttpTestRunner) WithJsonBody ¶
func (r *HttpTestRunner) WithJsonBody(typedBody any) *HttpTestRunner
WithJsonBody set HttpTestRunner.body using an interface
func (*HttpTestRunner) WithMethod ¶
func (r *HttpTestRunner) WithMethod(method string) *HttpTestRunner
WithMethod set the method to be used by the runner
func (*HttpTestRunner) WithPath ¶
func (r *HttpTestRunner) WithPath(path string) *HttpTestRunner
WithPath set the path to be executed by the runner
func (*HttpTestRunner) WithStringBody ¶
func (r *HttpTestRunner) WithStringBody(stringBody string) *HttpTestRunner
WithStringBody set HttpTestRunner.body using a string
func (*HttpTestRunner) WithValues ¶
func (r *HttpTestRunner) WithValues(values url.Values) *HttpTestRunner
WithValues set the url values to be used by the runner