Documentation ¶
Index ¶
- Constants
- Variables
- func InitializeContext(ctx context.Context) context.Context
- type ContextKey
- type Logger
- type RequestParams
- type Session
- func (s *Session) ConfigureCredentials(ctx context.Context, username, password string)
- func (s *Session) ConfigureEndpoint(ctx context.Context, endpoint string)
- func (s *Session) ConfigureHeaders(ctx context.Context, headers map[string][]string)
- func (s *Session) ConfigureInsecureSkipVerify(ctx context.Context)
- func (s *Session) ConfigureNoRedirection(ctx context.Context)
- func (s *Session) ConfigurePath(httpPath string)
- func (s *Session) ConfigureQueryParams(params map[string][]string)
- func (s *Session) ConfigureRequestBody(ctx context.Context, message interface{})
- func (s *Session) ConfigureRequestBodyJSONFile(ctx context.Context, bodyParams schema.Params) error
- func (s *Session) ConfigureRequestBodyJSONFileWithout(ctx context.Context, bodyParams schema.Params, params []string) error
- func (s *Session) ConfigureRequestBodyJSONProperties(ctx context.Context, props map[string]interface{}) error
- func (s *Session) ConfigureRequestBodyURLEncodedProperties(ctx context.Context, props map[string][]string) error
- func (s *Session) GetURL(ctx context.Context) (string, error)
- func (s *Session) SendHTTPRequest(ctx context.Context, method string) error
- func (s *Session) SendRequest(ctx context.Context, uRL, method, endpoint, apiKey string) error
- func (s *Session) SendRequestWithBody(ctx context.Context, uRL, method, endpoint string, bodyParams schema.Params, ...) error
- func (s *Session) SendRequestWithBodyModifyingFields(ctx context.Context, uRL, method, endpoint string, bodyParams schema.Params, ...) error
- func (s *Session) SendRequestWithBodyWithoutFields(ctx context.Context, uRL, method, endpoint string, bodyParams schema.Params, ...) error
- func (s *Session) SendRequestWithFilters(ctx context.Context, uRL, method, endpoint, apiKey, filters string) error
- func (s *Session) SendRequestWithMultipartBody(ctx context.Context, reqParams RequestParams, fileField, file string) error
- func (s *Session) SendRequestWithPath(ctx context.Context, uRL, method, endpoint, requestPath, apiKey string) error
- func (s *Session) SendRequestWithPathAndBody(ctx context.Context, uRL, method, endpoint, requestPath string, ...) error
- func (s *Session) SendRequestWithQueryParams(ctx context.Context, uRL, method, endpoint, apiKey string, t *godog.Table) error
- func (s *Session) SendRequestWithoutBackslash(ctx context.Context, uRL, method, endpoint, apiKey string) error
- func (s *Session) SetHTTPResponseTimeout(ctx context.Context, timeout int)
- func (s *Session) StoreResponseBodyJSONPropertyInContext(ctx context.Context, key, ctxtKey string) error
- func (s *Session) StoreResponseHeaderInContext(ctx context.Context, header, ctxtKey string) error
- func (s *Session) URL() (*url.URL, error)
- func (s *Session) ValidateNotResponseHeaders(ctx context.Context, expectedHeaders []string) error
- func (s *Session) ValidateResponseBodyEmpty(ctx context.Context) error
- func (s *Session) ValidateResponseBodyJSONFile(ctx context.Context, responseParams schema.Params, respDataLocation string) error
- func (s *Session) ValidateResponseBodyJSONFileModifying(ctx context.Context, responseParams schema.Params, t *godog.Table) error
- func (s *Session) ValidateResponseBodyJSONFileWithout(ctx context.Context, responseParams schema.Params, respDataLocation string, ...) error
- func (s *Session) ValidateResponseBodyJSONProperties(ctx context.Context, props map[string]interface{}) error
- func (s *Session) ValidateResponseBodyJSONSchema(ctx context.Context, schemaName string) error
- func (s *Session) ValidateResponseBodyText(ctx context.Context, expectedText string) error
- func (s *Session) ValidateResponseFromJSONFile(response interface{}, respDataLocation string) error
- func (s *Session) ValidateResponseHeaders(ctx context.Context, expectedHeaders map[string][]string) error
- func (s *Session) ValidateResponseTimedout(ctx context.Context) error
- func (s *Session) ValidateStatusCode(ctx context.Context, expectedCode int) error
- type Steps
Constants ¶
const ( InvalidPath = "[CONF:apiKey.invalid_apiKey]" NilString = "%nil%" Slash = "/" DefaultTestURL = "https://jsonplaceholder.typicode.com/" )
Variables ¶
var AuthHeaders = map[string]string{
"X-API-KEY": "apikey",
"Authorization": "jwt",
}
Functions ¶
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey defines a type to store the HTTP session in context.Context.
type Logger ¶
Logger logs in a configurable file.
func GetLogger ¶
func GetLogger() *Logger
GetLogger returns the logger for HTTP requests and responses. If the logger is not created yet, it creates a new instance of Logger.
func (Logger) LogRequest ¶
LogRequest logs an HTTP request in the configured log file.
func (Logger) LogResponse ¶
LogResponse logs an HTTP response in the configured log file.
func (Logger) LogTimeout ¶
LogTimeout logs an HTTP response with timeout in the configured log file.
type RequestParams ¶ added in v0.18.0
type Session ¶
type Session struct { Request model.Request Response model.Response NoRedirect bool InsecureSkipVerify bool Timeout time.Duration Timedout bool }
Session contains the information of a HTTP session (request and response).
func GetSession ¶
GetSession returns the HTTP session stored in context. Note that the context should be previously initialized with InitializeContext function.
func (*Session) ConfigureCredentials ¶
func (*Session) ConfigureEndpoint ¶
ConfigureEndpoint configures the HTTP endpoint.
func (*Session) ConfigureHeaders ¶
ConfigureHeaders stores a table of HTTP headers in the application context.
func (*Session) ConfigureInsecureSkipVerify ¶ added in v0.16.1
ConfigureInsecureSkipVerify configures insecure skip verify for the HTTP client in HTTPS calls.
func (*Session) ConfigureNoRedirection ¶
ConfigureNoRedirection configures no redirection for the HTTP client.
func (*Session) ConfigurePath ¶
ConfigurePath configures the path of the HTTP endpoint. It configures a resource path in the application context. The API endpoint and the resource path are composed when invoking the HTTP server.
func (*Session) ConfigureQueryParams ¶
ConfigureQueryParams stores a table of query parameters in the application context.
func (*Session) ConfigureRequestBody ¶ added in v0.17.0
ConfigureRequestBodyJSONText writes the body in the HTTP request as a JSON from text.
func (*Session) ConfigureRequestBodyJSONFile ¶
func (s *Session) ConfigureRequestBodyJSONFile( ctx context.Context, bodyParams schema.Params, ) error
ConfigureRequestBodyJSONFile writes the body in the HTTP request as a JSON from file.
func (*Session) ConfigureRequestBodyJSONFileWithout ¶
func (s *Session) ConfigureRequestBodyJSONFileWithout( ctx context.Context, bodyParams schema.Params, params []string) error
ConfigureRequestBodyJSONFileWithout writes the body in the HTTP request as a JSON from file without given values.
func (*Session) ConfigureRequestBodyJSONProperties ¶
func (s *Session) ConfigureRequestBodyJSONProperties( ctx context.Context, props map[string]interface{}) error
ConfigureRequestBodyJSONProperties writes the body in the HTTP request as a JSON with properties.
func (*Session) ConfigureRequestBodyURLEncodedProperties ¶
func (s *Session) ConfigureRequestBodyURLEncodedProperties( ctx context.Context, props map[string][]string) error
ConfigureRequestBodyURLEncodedProperties writes the body in the HTTP request as x-www-form-urlencoded with properties.
func (*Session) SendHTTPRequest ¶
SendHTTPRequest sends a HTTP request using the configuration in the application context.
func (*Session) SendRequest ¶ added in v0.17.0
SendRequestWithoutBackslash send request without backslash.
func (*Session) SendRequestWithBody ¶ added in v0.17.0
func (s *Session) SendRequestWithBody( ctx context.Context, uRL, method, endpoint string, bodyParams schema.Params, apiKey string, ) error
SendRequestWithBody send request using body from JSON file located in schemas.
func (*Session) SendRequestWithBodyModifyingFields ¶ added in v0.17.0
func (s *Session) SendRequestWithBodyModifyingFields( ctx context.Context, uRL, method, endpoint string, bodyParams schema.Params, apiKey string, t *godog.Table, ) error
SendRequestWithBodyModifyingFields send request using body from JSON file located in schemas modifying fields.
func (*Session) SendRequestWithBodyWithoutFields ¶ added in v0.17.0
func (s *Session) SendRequestWithBodyWithoutFields( ctx context.Context, uRL, method, endpoint string, bodyParams schema.Params, apiKey string, t *godog.Table, ) error
SendRequestWithBodyWithoutFields send request using body from JSON file located in schemas without fields.
func (*Session) SendRequestWithFilters ¶ added in v0.17.0
func (s *Session) SendRequestWithFilters( ctx context.Context, uRL, method, endpoint, apiKey, filters string, ) error
SendRequestWithFilters send request using filters with query params.
func (*Session) SendRequestWithMultipartBody ¶ added in v0.18.0
func (s *Session) SendRequestWithMultipartBody( ctx context.Context, reqParams RequestParams, fileField, file string, ) error
SendRequestWithMultipartBody send request using multipart body.
func (*Session) SendRequestWithPath ¶ added in v0.17.0
func (s *Session) SendRequestWithPath( ctx context.Context, uRL, method, endpoint, requestPath, apiKey string, ) error
SendRequestWithPath send request with path.
func (*Session) SendRequestWithPathAndBody ¶ added in v0.17.0
func (s *Session) SendRequestWithPathAndBody( ctx context.Context, uRL, method, endpoint, requestPath string, bodyParams schema.Params, apiKey string, ) error
SendRequestWithPathAndBody send request with path and JSON body.
func (*Session) SendRequestWithQueryParams ¶ added in v0.17.0
func (s *Session) SendRequestWithQueryParams( ctx context.Context, uRL, method, endpoint, apiKey string, t *godog.Table, ) error
SendRequestWithQueryParams send request using with query params.
func (*Session) SendRequestWithoutBackslash ¶ added in v0.17.0
func (s *Session) SendRequestWithoutBackslash( ctx context.Context, uRL, method, endpoint, apiKey string, ) error
SendRequestWithoutBackslash send request without backslash.
func (*Session) SetHTTPResponseTimeout ¶
SetHTTPResponseTimeout configures a response timeout in milliseconds.
func (*Session) StoreResponseBodyJSONPropertyInContext ¶
func (s *Session) StoreResponseBodyJSONPropertyInContext( ctx context.Context, key, ctxtKey string) error
StoreResponseBodyJSONPropertyInContext extracts a JSON property from the HTTP response body and stores it in the context.
func (*Session) StoreResponseHeaderInContext ¶
StoreResponseHeaderInContext stores in context a header of the HTTP response. If the header does not exist, the context value is empty. This method does not support multiple headers with the same name. It just stores one of them.
func (*Session) ValidateNotResponseHeaders ¶
ValidateNotResponseHeaders checks that a set of response headers are not included in HTTP response.
func (*Session) ValidateResponseBodyEmpty ¶
ValidateResponseBodyEmpty validates that the response body is empty. It checks the Content-Length header and the response body buffer.
func (*Session) ValidateResponseBodyJSONFile ¶
func (s *Session) ValidateResponseBodyJSONFile( ctx context.Context, responseParams schema.Params, respDataLocation string) error
ValidateResponseBodyJSONFile validates the response body against the JSON in File.
func (*Session) ValidateResponseBodyJSONFileModifying ¶ added in v0.17.0
func (s *Session) ValidateResponseBodyJSONFileModifying( ctx context.Context, responseParams schema.Params, t *godog.Table, ) error
ValidateResponseBodyJSONFileModifying validates the response body against the JSON in File modifying params.
func (*Session) ValidateResponseBodyJSONFileWithout ¶
func (s *Session) ValidateResponseBodyJSONFileWithout( ctx context.Context, responseParams schema.Params, respDataLocation string, t *godog.Table) error
ValidateResponseBodyJSONFileWithout validates the response body against the JSON in File without params.
func (*Session) ValidateResponseBodyJSONProperties ¶
func (s *Session) ValidateResponseBodyJSONProperties( ctx context.Context, props map[string]interface{}) error
ValidateResponseBodyJSONProperties validates a list of properties in the JSON body of the HTTP response.
func (*Session) ValidateResponseBodyJSONSchema ¶
ValidateResponseBodyJSONSchema validates the response body against the JSON schema.
func (*Session) ValidateResponseBodyText ¶
ValidateResponseBodyText validates that the response body payload is the expected text.
func (*Session) ValidateResponseFromJSONFile ¶
func (s *Session) ValidateResponseFromJSONFile( response interface{}, respDataLocation string) error
ValidateResponseFromJSONFile validates the response body against the response from JSON File.
func (*Session) ValidateResponseHeaders ¶
func (s *Session) ValidateResponseHeaders( ctx context.Context, expectedHeaders map[string][]string) error
ValidateResponseHeaders checks a set of response headers.
func (*Session) ValidateResponseTimedout ¶
ValidateResponseTimedout checks if the HTTP client timed out without receiving a response.
type Steps ¶
type Steps struct { }
Steps type is responsible to initialize the HTTP client steps in godog framework.
func (Steps) InitializeSteps ¶
InitializeSteps adds client HTTP steps to the scenario context. It implements StepsInitializer interface. It returns a new context (context is immutable) with the HTTP Context.