testutils

package
v0.0.0-...-b1b50a1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 11 Imported by: 0

README

Test utils

Various test utilities

Documentation

Index

Constants

View Source
const (
	// CallFromTestFile to use when Assert() is used in a test file
	CallFromTestFile = 2
	// CallFromHelperMethod to user when Asset() is used from a helper method
	CallFromHelperMethod = 3
)

Variables

This section is empty.

Functions

func Assert

func Assert(tb testing.TB, callerSkip int, condition bool, msg string, v ...interface{})

Assert fails the test if the condition is false.

func CheckHTTPStatus

func CheckHTTPStatus(t *testing.T, callDepth int, rr *httptest.ResponseRecorder, expectedStatus int)

CheckHTTPStatus makes a test fails if the response recorder status code is not the expected code

func Equals

func Equals(tb testing.TB, callerSkip int, exp, act interface{})

Equals fails the test if exp is not equal to act.

func Ok

func Ok(tb testing.TB, callerSkip int, err error)

Ok fails the test if an err is not nil.

Types

type APITestInfo

type APITestInfo struct {
	Path               string
	Method             string
	Version            string // default to core.APIv1
	Payload            interface{}
	AuthToken          string
	Headers            map[string]string
	ExpectedHTTPStatus int
}

APITestInfo gathers info for a single test run

type APITester

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

APITester saves a router and run tests against the saved router

func NewAPITester

func NewAPITester(api *core.API) *APITester

NewAPITester build an APITester from a core.API reference. router is built in microservice mode

func (*APITester) ServeHTTP

func (at *APITester) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*APITester) ServeReq

func (at *APITester) ServeReq(req *http.Request) *httptest.ResponseRecorder

ServeReq serves a given request and returns the ResponseRecorder for the request

func (*APITester) TestPath

func (at *APITester) TestPath(t *testing.T, apiTest APITestInfo) *httptest.ResponseRecorder

TestPath tests a single API call and returns the generated ResponseRecorder

Jump to

Keyboard shortcuts

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