Documentation ¶
Index ¶
- Constants
- type Checker
- type Option
- type Tester
- func (tt *Tester) Cb(callback func(*http.Response))
- func (tt *Tester) Check() *Tester
- func (tt *Tester) ContainsBody(segment []byte) *Tester
- func (tt *Tester) ContainsString(substr string) *Tester
- func (tt *Tester) HasBody(expected []byte) *Tester
- func (tt *Tester) HasCookie(key, expectedValue string) *Tester
- func (tt *Tester) HasHeader(key, expectedValue string) *Tester
- func (tt *Tester) HasHeaders(headers map[string]string) *Tester
- func (tt *Tester) HasJSON(expected any) *Tester
- func (tt *Tester) HasJson(expected any) *Testerdeprecated
- func (tt *Tester) HasStatus(expected int) *Tester
- func (tt *Tester) HasString(expected string) *Tester
- func (tt *Tester) HasXML(expected any) *Tester
- func (tt *Tester) HasXml(expected any) *Testerdeprecated
- func (tt *Tester) MustContainsBody(segment []byte) *Tester
- func (tt *Tester) MustContainsString(substr string) *Tester
- func (tt *Tester) MustHasBody(expected []byte) *Tester
- func (tt *Tester) MustHasCookie(key, expectedValue string) *Tester
- func (tt *Tester) MustHasHeader(key, expectedValue string) *Tester
- func (tt *Tester) MustHasHeaders(headers map[string]string) *Tester
- func (tt *Tester) MustHasJSON(expected any) *Tester
- func (tt *Tester) MustHasStatus(expected int) *Tester
- func (tt *Tester) MustHasString(expected string) *Tester
- func (tt *Tester) MustHasXML(expected any) *Tester
- func (tt *Tester) MustNotContainsBody(segment []byte) *Tester
- func (tt *Tester) MustNotContainsString(substr string) *Tester
- func (tt *Tester) NotContainsBody(segment []byte) *Tester
- func (tt *Tester) NotContainsString(substr string) *Tester
- func (tt *Tester) WithBasicAuth(user, pass string) *Tester
- func (tt *Tester) WithBearerAuth(token string) *Tester
- func (tt *Tester) WithBody(body []byte) *Tester
- func (tt *Tester) WithCookie(key, value string) *Tester
- func (tt *Tester) WithHeader(key, value string) *Tester
- func (tt *Tester) WithHeaders(headers map[string]string) *Tester
- func (tt *Tester) WithHostHeader(value string) *Tester
- func (tt *Tester) WithJSON(expected any) *Tester
- func (tt *Tester) WithJson(expected any) *Testerdeprecated
- func (tt *Tester) WithString(body string) *Tester
- func (tt *Tester) WithXML(body any) *Tester
- func (tt *Tester) WithXml(body any) *Testerdeprecated
- type TestingT
Constants ¶
const ( // DefaultClientTimeout is the default timeout for requests made by checker. DefaultClientTimeout = 5 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker represents the HTTP checker without testing.T.
func (*Checker) PersistCookie ¶
PersistCookie - enables a cookie to be preserved between requests
func (*Checker) Test ¶
Test - Prepare for testing some part of code which lives on provided path and method.
func (*Checker) TestRequest ¶
TestRequest - If you want to provide you custom http.Request instance, you can do it using this method In this case internal http.Request instance won't be created, and passed instance will be used for making request
func (*Checker) UnpersistCookie ¶
UnpersistCookie - the specified cookie will not be preserved during requests anymore
type Option ¶
type Option func(*Checker)
Option represents the option for the checker.
func CheckRedirect ¶ added in v1.4.0
CheckRedirect sets the policy of redirection to the HTTP client.
func ClientTimeout ¶
ClientTimeout sets the client timeout.
func NoRedirect ¶ added in v1.4.0
func NoRedirect() Option
NoRedirect is the alias of the following:
CheckRedirect(func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse })
Client returns ErrUseLastResponse, the next request is not sent and the most recent response is returned with its body unclosed.
type Tester ¶
type Tester struct { *Checker // contains filtered or unexported fields }
Tester represents the HTTP tester having TestingT.
func (*Tester) Check ¶
Check - Will make request to built request object. After request is made, it will save response object for future assertions Responsibility of this method is also to start and stop HTTP server
func (*Tester) ContainsBody ¶
ContainsBody checks if the body contains provided [] byte data.
func (*Tester) ContainsString ¶
ContainsString converts the response to a string type and then checks it containing the given string.
func (*Tester) HasCookie ¶
HasCookie checks if the response contains cookie with provided key and value.
func (*Tester) HasHeader ¶
HasHeader checks if the response contains header on provided key with provided value.
func (*Tester) HasHeaders ¶
HasHeaders checks if the response contains a provided headers map.
func (*Tester) HasString ¶
HasString converts the response to a string type and then compares it with the given string.
func (*Tester) MustContainsBody ¶ added in v1.7.0
MustContainsBody checks if the body contains provided [] byte data.
func (*Tester) MustContainsString ¶ added in v1.7.0
MustContainsString converts the response to a string type and then checks it containing the given string.
func (*Tester) MustHasBody ¶ added in v1.7.0
MustHasBody checks if the body is equal to provided []byte data.
func (*Tester) MustHasCookie ¶ added in v1.7.0
MustHasCookie checks if the response contains cookie with provided key and value.
func (*Tester) MustHasHeader ¶ added in v1.7.0
MustHasHeader checks if the response contains header on provided key with provided value.
func (*Tester) MustHasHeaders ¶ added in v1.7.0
MustHasHeaders checks if the response contains a provided headers map.
func (*Tester) MustHasJSON ¶ added in v1.7.0
MustHasJSON checks if the response body contains json with provided value.
func (*Tester) MustHasStatus ¶ added in v1.7.0
MustHasStatus checks if the response status is equal to that provided.
func (*Tester) MustHasString ¶ added in v1.7.0
MustHasString converts the response to a string type and then compares it with the given string.
func (*Tester) MustHasXML ¶ added in v1.7.0
MustHasXML checks if body contains xml with provided value.
func (*Tester) MustNotContainsBody ¶ added in v1.7.0
MustNotContainsBody checks if the body does not contain provided [] byte data.
func (*Tester) MustNotContainsString ¶ added in v1.7.0
MustNotContainsString converts the response to a string type and then checks if it does not contain the given string.
func (*Tester) NotContainsBody ¶
NotContainsBody checks if the body does not contain provided [] byte data.
func (*Tester) NotContainsString ¶
NotContainsString converts the response to a string type and then checks if it does not contain the given string.
func (*Tester) WithBasicAuth ¶
WithBasicAuth is an alias to set basic auth in the request header.
func (*Tester) WithBearerAuth ¶ added in v1.5.0
WithBearerAuth is an alias to set bearer auth in the request header.
func (*Tester) WithCookie ¶
WithCookie puts cookie on the request.
func (*Tester) WithHeader ¶
WithHeader puts header on the request.
func (*Tester) WithHeaders ¶
WithHeaders puts a map of headers on the request.
func (*Tester) WithHostHeader ¶ added in v1.6.0
WithHostHeader puts "Host" header on the request.
func (*Tester) WithString ¶
WithString adds the string to the body.