http

package
v0.0.0-...-f96b470 Latest Latest
Warning

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

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

Documentation

Overview

Package http contains the HTTP/REST test scenario implementation.

Index

Constants

View Source
const (
	AssertionMethodEqual    assertionMethod = "equal"
	AssertionMethodRegex    assertionMethod = "regex"
	AssertionMethodNotEmpty assertionMethod = "not_empty"
)

Different assertion methods.

View Source
const (
	ValidationBody    validationType = "body"
	ValidationStatus  validationType = "status"
	ValidationHeaders validationType = "headers"
)

Different validation types.

Variables

This section is empty.

Functions

func AssertionMethod

func AssertionMethod(method string) assertionMethod

AssertionMethod returns an assertion method for a given string.

Types

type Assertion

type Assertion struct {
	Key       string
	Assertion assertionMethod
	Value     string
}

Assertion represents an assertion, as part of a validation.

type AssertionError

type AssertionError struct {
	StepName   string
	RequestURL string
	Msg        string
}

AssertionError is an error for when an assertion fails.

func (AssertionError) Error

func (e AssertionError) Error() string

type Client

type Client interface {
	Do(req *http.Request) (*http.Response, error)
}

Client is the interface for perfoming HTTP requests.

type ErrInvalidPathReplacement

type ErrInvalidPathReplacement struct {
	// contains filtered or unexported fields
}

ErrInvalidPathReplacement is an error for when a replacement json path is not found in the defined step's JSON output.

func (ErrInvalidPathReplacement) Error

type ErrJSONKeyNotFound

type ErrJSONKeyNotFound struct {
	StepName, Key, Body string
}

ErrJSONKeyNotFound is an error for when a JSON key for dynamic input replacement is not found in the defined step's JSON output.

func (ErrJSONKeyNotFound) Error

func (e ErrJSONKeyNotFound) Error() string

type ErrNonExecutedStep

type ErrNonExecutedStep struct {
	StepName, NonExecutedStepName string
}

ErrNonExecutedStep is an error for when a step is not executed but is required for dynamic input replacement.

func (ErrNonExecutedStep) Error

func (e ErrNonExecutedStep) Error() string

type ExecuteResult

type ExecuteResult struct {
	Name               string
	TotalExecutionTime time.Duration
	TotalAssertions    int
	StepResults        []*ExecuteStepResult
	Success            bool
}

ExecuteResult is the result of executing a scenario.

type ExecuteStepResult

type ExecuteStepResult struct {
	Name            string
	Assertions      int
	URL             string
	RequestDuration time.Duration
	Duration        time.Duration
	Retries         int
	Success         bool
}

ExecuteStepResult is the result of executing a step.

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

Executor is the http test executor implementation.

func NewExecutor

func NewExecutor(scenario *Scenario, opts ...Opts) (*Executor, error)

NewExecutor creates a new HTTP test scenario executor.

func (Executor) Play

func (e Executor) Play() (*ExecuteResult, error)

Play executes the scenario.

type Header struct {
	Name  string
	Value string
}

Header represents a HTTP header.

type InputReplacement

type InputReplacement struct {
	StepName         string
	JSONKey          string
	ReplacementValue string
}

InputReplacement is a struct for replacing dynamic inputs in a step.

type Opts

type Opts func(*options)

Opts is a function for setting options on a scenario.

func WithHTTPClient

func WithHTTPClient(client Client) Opts

WithHTTPClient sets the HTTP client to use for the scenario.

func WithLogger

func WithLogger(logger *slog.Logger) Opts

WithLogger sets the logger to use for the scenario.

type Request

type Request struct {
	Method  string
	URL     string
	Headers []*Header
	Body    string
}

Request represents a HTTP request.

type RequestResult

type RequestResult struct {
	Body    []byte
	Status  int
	Headers http.Header
}

RequestResult represents the result of an HTTP request.

type Retry

type Retry struct {
	Attempts int           `yaml:"attempts"`
	Timeout  time.Duration `yaml:"timeout"`
}

Retry for a single step.

type Scenario

type Scenario struct {
	Name  string
	Steps []*Step
}

Scenario is the main struct for a test scenario to be executed.

type Step

type Step struct {
	Name          string
	Request       *Request
	Validation    *Validation
	RequestResult *RequestResult
	IsExecuted    bool
	Retry         *Retry
}

Step represents a step in a scenario.

type Validation

type Validation struct {
	Body    []*Assertion
	Status  *Assertion
	Headers []*Assertion
}

Validation represents the validation of a step.

Jump to

Keyboard shortcuts

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