testrunner

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BodyAsJson

func BodyAsJson(t *testing.T, resp *http.Response, jsonBody any)

BodyAsJson unmarshal the body of a request to json

func BodyAsString

func BodyAsString(t *testing.T, resp *http.Response) string

BodyAsString returns the body of a request as string

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

Jump to

Keyboard shortcuts

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