domain

package
v0.0.0-...-8ce64ba Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package extract defines all the possible extraction methods that can be applied on a response.

Signatures

it is important for consistency that each extractor follow the same function signature:

func(r RequestTest, resp *http.Response, env map[string]interface{})

this will allow easier refactoring or interfacing later on if this becomes necessary.

Package format defines the format of a Litmus test file, as represented in code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Body

func Body(r *RequestTest, resp *http.Response, env map[string]interface{}) error

Payload - checks the body against the expected value

func Header(r *RequestTest, resp *http.Response, env map[string]interface{}) error

Header - extracts a header value and checks it against the expected value

func ProcessResponse

func ProcessResponse(r *RequestTest, resp *http.Response, env map[string]interface{}) error

func StatusCode

func StatusCode(r *RequestTest, resp *http.Response, _ map[string]interface{}) error

StatusCode - extracts the status code and checks it against the expected value

Types

type BodyGetter

type BodyGetter interface {
	Get(path string, body []byte) (value string, err error)
}

BodyGetter defines the behavior or something that can extract information from a response body.

func NewBodyGetter

func NewBodyGetter(resp *http.Response) (e BodyGetter, err error)

NewBodyGetter returns the body extracter based on the Content-Type found in the response headers.

type GetterConfig

type GetterConfig struct {
	Path     string `toml:"path" yaml:"path"`
	Set      string `toml:"set" yaml:"set"`
	Type     string `toml:"type" yaml:"type"`
	Expected string `toml:"exp" yaml:"exp"`
}

GetterConfig provides the information required to get data from a response.

type GetterConfigs

type GetterConfigs []GetterConfig

GetterConfigs is a slice of GetterConfig

type HeaderGetter

type HeaderGetter struct{}

HeaderGetter extracts information from response headers.

func (*HeaderGetter) Get

func (e *HeaderGetter) Get(path string, header http.Header) (value string, err error)

Get extracts a value out of request headers.

type JSONBodyGetter

type JSONBodyGetter struct{}

JSONBodyGetter extracts information from a response body using JSON dot notation.

func (*JSONBodyGetter) Get

func (e *JSONBodyGetter) Get(path string, body []byte) (value string, err error)

Get extracts a value out of a JSON body using JSON dot notation.

type KeyValuePair

type KeyValuePair struct {
	Key   string
	Value string
}

KeyValuePair allows a map to be expressed in slice form.

type KeyValuePairs

type KeyValuePairs []KeyValuePair

KeyValuePairs is a slice of KeyValuePair.

func (*KeyValuePairs) Set

func (k *KeyValuePairs) Set(value string) error

Set adds an item to KeyValuePairs.

func (*KeyValuePairs) String

func (k *KeyValuePairs) String() string

String returns the string representation of KeyValuePairs.

func (*KeyValuePairs) Type

func (k *KeyValuePairs) Type() string

Type returns a string representation of the type of KeyValuePairs

type Litmus

type Litmus struct {
	// test is singular to enable singular dot notation in the file
	Test []RequestTest
}

type RequestTest

type RequestTest struct {
	Name          string                 `toml:"name" yaml:"name"`
	Method        string                 `toml:"method" yaml:"method"`
	URL           string                 `toml:"url" yaml:"url"`
	Headers       map[string]string      `toml:"headers" yaml:"headers"`
	Query         map[string]string      `toml:"query" yaml:"query"`
	Payload       string                 `toml:"payload" yaml:"payload"`
	BodyModifiers map[string]interface{} `toml:"bodymod" yaml:"bodymod"`
	Body          map[string]interface{} `toml:"body" yaml:"body"`
	Head          map[string]interface{} `toml:"head" yaml:"head"`
	WantsCode     int                    `toml:"wants_code" yaml:"wants_code"`
}

RequestTest defines all the necessary fields to define a Litmus test

func (*RequestTest) ApplyEnv

func (r *RequestTest) ApplyEnv(env map[string]interface{}) (err error)

type TestFile

type TestFile struct {
	// Litmus is the top level table
	Litmus Litmus
}

TestFile is the top level container element defining a Litmus test file

Jump to

Keyboard shortcuts

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