Documentation ¶
Index ¶
- func FindValueByCode(dataStruct []map[string]interface{}, code string, param string) (interface{}, error)
- func GetParamFromJSON(ctx context.Context, file, code, param string) (interface{}, error)
- func InitializeContext(ctx context.Context) context.Context
- func JSONEquals(expected interface{}, current interface{}) bool
- func LoadJSONData(file string) ([]byte, error)
- func UnmarshalJSONData(data []byte) ([]map[string]interface{}, error)
- type ContextKey
- type Logger
- type Request
- type Response
- type Session
- func (s *Session) AddToRequestMessageFromJSONFile(message interface{})
- 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) ConfigureNoRedirection(ctx context.Context)
- func (s *Session) ConfigurePath(ctx context.Context, path string)
- func (s *Session) ConfigureQueryParams(ctx context.Context, params map[string][]string)
- func (s *Session) ConfigureRequestBodyJSONFile(ctx context.Context, code, file string) error
- func (s *Session) ConfigureRequestBodyJSONFileWithout(ctx context.Context, code, file string, params []string) error
- func (s *Session) ConfigureRequestBodyJSONProperties(ctx context.Context, props map[string]interface{}) error
- func (s *Session) ConfigureRequestBodyJSONText(ctx context.Context, message string)
- func (s *Session) ConfigureRequestBodyURLEncodedProperties(ctx context.Context, props map[string][]string) error
- func (s *Session) SendHTTPRequest(ctx context.Context, method string) error
- func (s *Session) SetHTTPResponseTimeout(ctx context.Context, timeout int)
- func (s *Session) StoreResponseBodyJSONPropertyInContext(ctx context.Context, key string, ctxtKey string) error
- func (s *Session) StoreResponseHeaderInContext(ctx context.Context, header string, 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, code, file, respDataLocation string) error
- func (s *Session) ValidateResponseBodyJSONFileWithout(ctx context.Context, code, file, respDataLocation string, params []string) error
- func (s *Session) ValidateResponseBodyJSONProperties(ctx context.Context, props map[string]interface{}) error
- func (s *Session) ValidateResponseBodyJSONSchema(ctx context.Context, schema 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 ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindValueByCode ¶
func FindValueByCode(dataStruct []map[string]interface{}, code string, param string) (interface{}, error)
FindValueByCode Find value by code and param from dataStruct
func GetParamFromJSON ¶
GetParamFromJSON Retrieve values from JSON structure file assets
func InitializeContext ¶
InitializeContext adds the HTTP session to the context. The new context is returned because context is immutable.
func JSONEquals ¶
func JSONEquals(expected interface{}, current interface{}) bool
JSONEquals Check if unmarshalled JSON maps are equal
func LoadJSONData ¶
LoadJSONData Load file contents into bytes
func UnmarshalJSONData ¶
UnmarshalJSONData Unmarshal bytes to json map struct
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey defines a type to store the HTTP session in context.Context.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger logs the HTTP request and response 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 NewLogger ¶
NewLogger creates an instance of the logger. It configures the file path where the HTTP request and response are written.
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 Request ¶
type Request struct { // Endpoint of the HTTP server. It might include a base path. Endpoint string // Path of the API endpoint. This path is considered with the endpoint to invoke the HTTP server. Path string // Query parameters QueryParams map[string][]string // Request headers Headers map[string][]string // HTTP method Method string // Request body as slice of bytes RequestBody []byte // Username for basic authentication Username string // Password for basic authentication Password string }
Request information of the Session.
func (*Request) AddJSONHeaders ¶
func (r *Request) AddJSONHeaders()
AddJSONHeaders adds json headers to Request if they are null
type Response ¶
type Response struct { // HTTP response Response *http.Response // Response body as slice of bytes ResponseBody []byte }
Response information of the session.
type Session ¶
type Session struct { Request Request Response Response NoRedirect 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) AddToRequestMessageFromJSONFile ¶
func (s *Session) AddToRequestMessageFromJSONFile(message interface{})
AddToRequestMessageFromJSONFile adds to Request Body the message from JSON file
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) 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) ConfigureRequestBodyJSONFile ¶
ConfigureRequestBodyJSONFile writes the body in the HTTP request as a JSON from file.
func (*Session) ConfigureRequestBodyJSONFileWithout ¶
func (s *Session) ConfigureRequestBodyJSONFileWithout(ctx context.Context, code, file string, 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) ConfigureRequestBodyJSONText ¶
ConfigureRequestBodyJSONText // ConfigureRequestBodyJSONText writes the body in the HTTP request as a JSON from text.
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) SetHTTPResponseTimeout ¶
SetHTTPResponseTimeout configures a response timeout in milliseconds.
func (*Session) StoreResponseBodyJSONPropertyInContext ¶
func (s *Session) StoreResponseBodyJSONPropertyInContext(ctx context.Context, key string, ctxtKey string) error
StoreResponseBodyJSONPropertyInContext extracts a JSON property from the HTTP response body and stores it in the context.
func (*Session) StoreResponseHeaderInContext ¶
func (s *Session) StoreResponseHeaderInContext(ctx context.Context, header string, ctxtKey string) error
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, code, file, respDataLocation string) error
ValidateResponseBodyJSONFile validates the response body against the JSON in File.
func (*Session) ValidateResponseBodyJSONFileWithout ¶
func (s *Session) ValidateResponseBodyJSONFileWithout(ctx context.Context, code, file, respDataLocation string, params []string) 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 ¶
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.