config

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldMethod         = "method"
	FieldURL            = "url"
	FieldHeader         = "header"
	FieldBody           = "body"
	FieldRequests       = "requests"
	FieldConcurrency    = "concurrency"
	FieldInterval       = "interval"
	FieldRequestTimeout = "requestTimeout"
	FieldGlobalTimeout  = "globalTimeout"
	FieldTests          = "tests"
)

Variables

View Source
var FieldsUsage = map[string]string{
	FieldMethod:         "HTTP request method",
	FieldURL:            "HTTP request url",
	FieldHeader:         "HTTP request header",
	FieldBody:           "HTTP request body",
	FieldRequests:       "Number of requests to run, use duration as exit condition if omitted",
	FieldConcurrency:    "Number of connections to run concurrently",
	FieldInterval:       "Minimum duration between two non concurrent requests",
	FieldRequestTimeout: "Timeout for each HTTP request",
	FieldGlobalTimeout:  "Max duration of test",
	FieldTests:          "Test suite",
}

FieldsUsage is a record of all available config fields and their usage.

Functions

func IsField

func IsField(v string) bool

Types

type Global

type Global struct {
	Request Request
	Runner  Runner

	Tests []tests.Case
	// contains filtered or unexported fields
}

Global represents the global configuration of the runner. It must be validated using Global.Validate before usage.

func Default

func Default() Global

Default returns a default config that is safe to use.

func (Global) Equal

func (cfg Global) Equal(c Global) bool

Equal returns true if cfg and c are equal configurations.

func (Global) Override

func (cfg Global) Override(base Global) Global

Override returns a new Config by overriding the values of base with the values from the Config receiver. Only fields previously specified by the receiver via Config.WithFields are replaced. All other values from base are preserved.

The following example is equivalent to defaultConfig with the concurrency value from myConfig:

myConfig.
	WithFields(FieldConcurrency).
	Override(defaultConfig)

The following example is equivalent to defaultConfig, as no field as been tagged via WithFields by the receiver:

myConfig.Override(defaultConfig)

func (Global) String

func (cfg Global) String() string

String implements fmt.Stringer. It returns an indented JSON representation of Config for debugging purposes.

func (Global) Validate

func (cfg Global) Validate() error

Validate returns a non-nil InvalidConfigError if any of its fields does not meet the requirements.

func (Global) WithFields

func (cfg Global) WithFields(fields ...string) Global

WithField returns a new Global with the input fields marked as set. Accepted options are limited to existing Fields, other values are silently ignored.

type InvalidConfigError

type InvalidConfigError struct {
	Errors []error
}

InvalidConfigError is the errors returned by Global.Validate when values are missing or invalid.

func (*InvalidConfigError) Error

func (e *InvalidConfigError) Error() string

Error returns the joined errors of InvalidConfigError as a string.

type Request

type Request struct {
	Method string
	URL    *url.URL
	Header http.Header
	Body   RequestBody
}

Request contains the confing options relative to a single request.

func (Request) Value

func (r Request) Value() (*http.Request, error)

Value generates a *http.Request based on Request and returns it or any non-nil error that occurred.

func (Request) WithURL

func (r Request) WithURL(rawURL string) Request

WithURL sets the current Request with the parsed *url.URL from rawURL and returns it. Any errors is discarded as a Config can be invalid until Config.Validate is called. The url is always non-nil.

type RequestBody

type RequestBody struct {
	Type    string
	Content []byte
}

RequestBody represents a request body associated with a type. The type affects the way the content is processed. If Type == "file", Content is read as a filepath to be resolved. If Type == "raw", Content is attached as-is.

Note: only "raw" is supported at the moment.

func NewRequestBody

func NewRequestBody(typ, content string) RequestBody

NewRequestBody returns a Body initialized with the given type and content. For now, the only valid value for type is "raw".

type Runner

type Runner struct {
	Requests       int
	Concurrency    int
	Interval       time.Duration
	RequestTimeout time.Duration
	GlobalTimeout  time.Duration
}

Runner contains options relative to the runner.

Jump to

Keyboard shortcuts

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