tests

package
v0.0.0-...-a49728a Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package tests implements utility functions to help with API Gateway testing.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewIntegration

func NewIntegration(cfg *Config, cb CmdBuilder, bb BackendBuilder) (*Runner, []TestCase, error)

NewIntegration sets up a runner for the integration test and returns it with the parsed specs from the specs folder and an error signaling if something went wrong. It uses the default values for any nil argument

Example
runner, tcs, err := NewIntegration(nil, nil, nil)
if err != nil {
	fmt.Println(err)
	return
}
defer runner.Close()

for _, tc := range tcs {
	if err := runner.Check(tc); err != nil {
		fmt.Printf("%s: %s", tc.Name, err.Error())
		return
	}
}
Output:

signal: killed

Types

type BackendBuilder

type BackendBuilder interface {
	New(*Config) http.Server
}

BackendBuilder defines an interface for building a server as a backend for the tests

type CmdBuilder

type CmdBuilder interface {
	New(*Config) *exec.Cmd
}

CmdBuilder defines an interface for building the cmd to be managed by the Runner

type Config

type Config struct {
	BinPath         string
	CfgPath         string
	SpecsPath       string
	EnvironPatterns string
	BackendPort     int
	Delay           time.Duration
	HttpClient      *http.Client
}

Config contains options for running a test.

type Input

type Input struct {
	URL    string            `json:"url"`
	Method string            `json:"method"`
	Header map[string]string `json:"header"`
	Body   interface{}       `json:"body"`
}

Input is the definition of the request to send in a given TestCase

type Output

type Output struct {
	StatusCode int                 `json:"status_code"`
	Body       interface{}         `json:"body"`
	Header     map[string][]string `json:"header"`
}

Output contains the data required to verify the response received in a given TestCase

type Runner

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

Runner handles the integration test execution, by dealing with the request generation, response verification and the final shutdown

func (*Runner) Check

func (i *Runner) Check(tc TestCase) error

Check runs a test case, returning an error if something goes wrong

func (*Runner) Close

func (i *Runner) Close()

Close shuts down the mocked backend server and the process of the instance under test

type TestCase

type TestCase struct {
	Name string `json:"name"`
	Err  string `json:"error"`
	In   Input  `json:"in"`
	Out  Output `json:"out"`
}

TestCase defines a single case to be tested

Jump to

Keyboard shortcuts

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