test

package
v0.0.0-...-39e06ca Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(t test.T, url string, respBody interface{}, apiToken string) int

Delete request expecting JSON response

func DeleteWithoutBody

func DeleteWithoutBody(t test.T, url string, apiToken string) int

DeleteWithoutBody does DELETE request only expecting status code

func Get

func Get(t test.T, url string, respBody interface{}, apiToken string) int

Get request expecting JSON response

func GetWithoutBody

func GetWithoutBody(t test.T, url string, apiToken string) int

GetWithoutBody does GET request only expecting status code

func Post

func Post(t test.T, url string, reqBody interface{}, respBody interface{}, apiToken string) int

Post request with JSON body expecting JSON response

func Put

func Put(t test.T, url string, reqBody interface{}, respBody interface{}, apiToken string) int

Put request with JSON body expecting JSON response

func StartTestServer

func StartTestServer(routes []base.Routes, t test.T) (int, *app.ContextOut)

StartTestServer with specified routes. Returns chosen network port

func StartTestServerWithMiddleWare

func StartTestServerWithMiddleWare(middlewares base.Middlewares, routes []base.Routes, t test.T) (int, *app.ContextOut)

StartTestServerWithMiddleWare with specified middlewares and routes. Returns chosen network port

func StopTestServer

func StopTestServer(appCtx *app.ContextOut, t test.T)

StopTestServer gracefully

func StringifyHandlerFunc

func StringifyHandlerFunc(handlerFunc interface{}) string

StringifyHandlerFunc for comparisons in testing

Types

type HandlerFuncRegistrationOverride

type HandlerFuncRegistrationOverride func(method string, url string, registered func(http.ResponseWriter, *http.Request)) interface{}

HandlerFuncRegistrationOverride function type

type MockResponseWriter

type MockResponseWriter struct {

	// Header()
	HeaderReturn http.Header

	// Write()
	WriteBytesArg    []byte
	WriteIntReturn   int
	WriteErrorReturn error

	// WriteHeader()
	WriteHeaderStatusCodeArg int
}

MockResponseWriter is a test friendly implementation of http.ResponseWriter

func (*MockResponseWriter) Header

func (writer *MockResponseWriter) Header() http.Header

Header mocks 'http.ResponseWriter.Header() http.Header'

func (*MockResponseWriter) Write

func (writer *MockResponseWriter) Write(bytes []byte) (int, error)

Write mocks 'http.ResponseWriter.Write([]byte) (int,error)'

func (*MockResponseWriter) WriteHeader

func (writer *MockResponseWriter) WriteHeader(statusCode int)

WriteHeader mocks 'http.ResponseWriter.WriteHeader(int)'

type MockRoutesAgent

type MockRoutesAgent interface {
	base.RoutesAgent
	OverrideHandlerFuncRegistration(HandlerFuncRegistrationOverride)
	VerifyThatRoute(t test.T, url string) RouteVerifierFactory
}

MockRoutesAgent mocks base.RoutesAgent and adds test friendly features

func NewMockRoutesAgent

func NewMockRoutesAgent() MockRoutesAgent

NewMockRoutesAgent with test friendly features

type RouteVerifier

type RouteVerifier interface {
	UsesHandler(interface{}) RouteVerifier
}

RouteVerifier is used to verify proper configuration of HTTP routes

type RouteVerifierFactory

type RouteVerifierFactory interface {
	ForHTTPMethod(string) RouteVerifier
}

RouteVerifierFactory creates RouteVerifier instances

Jump to

Keyboard shortcuts

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