gg

package module
v0.0.0-...-6405d0c Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2020 License: MIT Imports: 12 Imported by: 0

README

groundgopher

A matrix style testing tool that allows you to run code for setup.
It allows you to define multiple lists of test manipulators and validators and all permutations of these lists will be run.

If your API has 2 parameters (time and filter) and an auth header you create 3 lists of tests:

auth time filter
none none none
valid current single param
expired +5m invalid param
invalid -5m all params

And groundgopher will run 4 * 4 * 4 * = 64 tests.

glossary

groundgopher

A combination of a groundhog and a gopher. And the groundhog was chosen because of groundhog day, as it resembles API development quite well. Attempting day after day to make the subtle changes to make everything right.

variable

A variable within groundgopher is a single parameter in the request that gets manipulated by a list of manipulators.
In the table above auth is a variable, in this case a header.
A variable is always a list of cases, but it is possible that a variable only has a single element

case

A case is a single element in a variable list. A case consists of a setup function and a validator function.

setup

The setup function manipulates the raw http request to make the required changes. For the auth variable of the example it will set a header (or not) to a certain value.

validator

The validator will validate the raw http response. In the expired case above, it will verify that the response is a 403 and that the body contains an error message.
It always returns a result

result

A result always includes wether the request was valid and if it isn't, it also includes the reason.

run

A run is the unique combination of a single case for every variable. It also includes the result and duration.

report

The report contains all the runs and also the outcome (false if any run failed)

TODO

  • add examples

acknowledgements

cartesian.go was heavily inspired (copied) from https://github.com/schwarmco/go-cartesian-product, thanks Joachim Swarm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Iter

func Iter(params ...Variable) chan []Case

Iter takes interface-slices and returns a channel, receiving cartesian products

Types

type Case

type Case struct {
	Name      string
	Disabled  bool
	Setup     func(*Ctx, *In)
	Validator func(*Ctx, Out) Result
	WantFail  bool
}

type Ctx

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

func (*Ctx) Get

func (gg *Ctx) Get(k string) string

func (*Ctx) Set

func (gg *Ctx) Set(k, v string)

type GroundGopher

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

func New

func New(opts ...Option) (*GroundGopher, error)

New returns a new gopher to run your tests

func (*GroundGopher) Add

func (gg *GroundGopher) Add(v Variable) error

func (*GroundGopher) Get

func (gg *GroundGopher) Get(k string) string

func (*GroundGopher) Run

func (gg *GroundGopher) Run(t *testing.T) Report

func (*GroundGopher) Set

func (gg *GroundGopher) Set(k, v string)

type In

type In struct {
	Req    http.Request
	Client http.Client
}

type Option

type Option func(gg *GroundGopher)

func WithHost

func WithHost(host string) Option

WithHost sets the hostname of the API you want to test

func WithVerbose

func WithVerbose(b bool) Option

WithVerbose toggles the optional verbose output

func WithWorkers

func WithWorkers(i int) Option

WithWorkers allows you to set the maximum number of parallel requests

type Out

type Out struct {
	Resp       *http.Response
	Body       []byte
	StatusCode int
	Duration   time.Duration
	UserAgent  string
}

func (*Out) JSONPathLookup

func (out *Out) JSONPathLookup(s string) (interface{}, error)

func (*Out) JSONPathLookupString

func (out *Out) JSONPathLookupString(s string) (string, error)

type Report

type Report struct {
	Amount    int
	Runs      []Run
	Successes int
	Fails     int
	Failed    bool
	TotalTime time.Duration
}

func (*Report) Summary

func (r *Report) Summary() string

type Result

type Result struct {
	Name       string
	Failed     bool
	WantedFail bool
	Reason     string
}

type Run

type Run struct {
	Cases      []string
	Results    []Result
	Body       string
	StatusCode int
	Duration   time.Duration
	WantFail   bool
	Failed     bool
}

type Variable

type Variable struct {
	Name  string
	Cases []Case
}

Jump to

Keyboard shortcuts

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