litmus

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package litmus provides common unit testing tools used in atomic projects

Index

Constants

This section is empty.

Variables

View Source
var (
	// Context is a mocked context.Context
	Context = mock.AnythingOfType("*context.valueCtx")

	// OperationArg is a convenience for referencing an arg
	OperationArg = func(a int, o ...int) *OperationRef {
		if len(o) > 0 {
			return &OperationRef{Index: o[0], Arg: a}
		}
		return &OperationRef{Index: 0, Arg: a}
	}

	// OperationReturn is a convenience for referencing a return
	OperationReturn = func(r int, o ...int) *OperationRef {
		if len(o) > 0 {
			return &OperationRef{Index: o[0], Return: r}
		}
		return &OperationRef{Index: 0, Return: r}
	}

	// NoRedirect forces no redirects
	NoRedirect = func(req *http.Request, via []*http.Request) error {
		return http.ErrUseLastResponse
	}
)

Functions

This section is empty.

Types

type Args

type Args []interface{}

Args are test args

type Mock added in v0.5.4

type Mock struct {
	mock.Mock
	// contains filtered or unexported fields
}

Mock is the litmus mock wrapper

func (*Mock) Called added in v0.5.4

func (m *Mock) Called(arguments ...interface{}) mock.Arguments

Called tells the mock object that a method has been called, and gets an array of arguments to return. Panics if the call is unexpected (i.e. not preceded by appropriate .On .Return() calls) If Call.WaitFor is set, blocks until the channel is closed or receives a message.

func (*Mock) MethodCalled added in v0.5.4

func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) mock.Arguments

MethodCalled wraps mock.MethodCalled to handle return stacks

type Operation added in v0.4.0

type Operation struct {
	// Name is the operation name
	Name string

	// Args is the operation args
	Args []interface{}

	// Returns in the operation returns
	Returns []interface{}

	// ReturnStack handles a return stack for multiple calls
	ReturnStack [][]interface{}

	// Optional backend for this operation
	Backend *mock.Mock
	// contains filtered or unexported fields
}

Operation is a backend operation

type OperationRef added in v0.4.0

type OperationRef struct {
	// Index refers the operation slice index
	Index int

	// Arg refers to the Args index
	Arg int

	// Return refers to the Returns index
	Return int
}

OperationRef is used to reference on operation

type RequestHandler added in v0.5.0

type RequestHandler func(backend interface{}, t *Test) (io.Reader, error)

RequestHandler can be used to generate a request body dynamically

type ReturnStack added in v0.5.4

type ReturnStack [][]interface{}

ReturnStack handles a return stack

type Returns

type Returns []interface{}

Returns are test returns

type Test

type Test struct {
	// Operations are the backend operations to prepare for test
	Operations []Operation

	// Method the http method
	Method string

	// The request path
	Path string

	// Query is the request query parameters
	Query url.Values

	// Request is the http request body put on the wire
	// []byte or string will be posted directly
	// if Request is *OperationRef that value will be used
	// everything else will be marshalled to json
	Request interface{}

	// RequestContentType is the request content type, default application/json
	RequestContentType string

	// ExpectedStatus is the expected http status
	ExpectedStatus int

	// ExpectedHeaders are expected response headers
	ExpectedHeaders map[string]string

	// ExpectedContentType is the expected content-type
	ExpectedContentType string

	// ExpectedResponse is expected wire response
	// []byte or string will be posted directly
	// if Request is *OperationRef that value will be used
	// everything else will be marshalled to json
	ExpectedResponse interface{}

	// Redirect overrides the http client redirect
	Redirect func(req *http.Request, via []*http.Request)

	// Setup is call before the request is executed
	Setup func(r *http.Request)
}

Test is a test requirements object

func (*Test) Do

func (t *Test) Do(backend *Mock, handler http.Handler, tt *testing.T)

Do executes the test

type Values added in v0.4.0

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

Values embeds a url values

func BeginQuery added in v0.4.0

func BeginQuery() Values

BeginQuery returns an intialized values

func (Values) Add added in v0.4.0

func (v Values) Add(key, value string) Values

Add adds a value

func (Values) Encode added in v0.5.0

func (v Values) Encode() string

Encode encodes the result

func (Values) EndQuery added in v0.4.0

func (v Values) EndQuery() url.Values

EndQuery returns the query values

Jump to

Keyboard shortcuts

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