Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AssertIsEqual = func(expected interface{}) AssertFunc { return func(t *testing.T, v interface{}) { assert.Equal(t, expected, v) } }
AssertIsEqual is a of type AssertFunc. It verifies that the value v is equal to the expected value.
var AssertIsSlice = func(t *testing.T, v interface{}) { if _, ok := v.([]interface{}); !ok { t.Errorf("could not assert that it's a slice, it's %s", reflect.ValueOf(v).Kind()) } }
AssertIsSlice asserts that v is a slice or an array
var AssertNotEmptyFunc = func(t *testing.T, v interface{}) { assert.NotEmpty(t, v) }
AssertNotEmptyFunc is a of type AssertFunc. It verifies that the value v is not empty.
var AssertSliceOfLen = func(n int) AssertFunc { return func(t *testing.T, v interface{}) { _v, ok := v.([]interface{}) if !ok { t.Errorf("could not assert that it's a slice, it's %s", reflect.ValueOf(v).Kind()) return } assert.Equal(t, n, len(_v)) } }
AssertSliceOfLen asserts that v is a slice or an array with n elements
Functions ¶
This section is empty.
Types ¶
type AssertFunc ¶
AssertFunc is a function that takes the testing.T pointer, a value v, and asserts whether v is good
type HandlerReqParams ¶
type HandlerReqParams struct { Route gopi.Route // Only one of HandlerFunc or Handler should be provided HandlerFunc http.HandlerFunc AuthBearerToken string Middlewares gopi.MiddlewareFuncs }
HandlerReqParams define a set of configuration that allow us to make repeated calls to Handler
func (HandlerReqParams) MakeHandlerRequest ¶
func (p HandlerReqParams) MakeHandlerRequest(content string, acceptedStatusCodes []int) (*http.Response, []byte, error)
MakeHandlerRequest makes an request to the handler specified in p, using the content. It errors if there is an error making the request, or if the received status code is not among the accepted status codes
type HandlerTest ¶
type HandlerTest struct { Name string Content string BeforeRunFunc func(*testing.T) AfterRunFunc func(*testing.T) AuthBearerTokenFunc func(*testing.T) string SkipAuthToken bool SkipBeforeTestFunc bool SkipAfterTestFunc bool WantStatusCode int WantContent string AssertContentFields map[string]AssertFunc // This only works if the response if a map (not if it's an array) AssertContentFuncs []AssertFunc WantErr bool WantErrMessage string LogResponse bool }
HandlerTest defines configuration for a single test run for a HandlerFunc. It is run run as part of the TestSuite
type TestSuite ¶
type TestSuite struct { Route gopi.Route AuthBearerTokenFunc func(*testing.T) string AuthMiddlewareHandler mux.MiddlewareFunc AfterTestFunc func(*testing.T) BeforeTestFunc func(*testing.T) }
TestSuite defines a configuration that wraps a bunch of individual tests for a single HandlerFunc
func (TestSuite) RunHandlerTest ¶
func (ts TestSuite) RunHandlerTest(t *testing.T, tt HandlerTest)
RunHandlerTest run all the HandlerTest tt
func (TestSuite) RunHandlerTests ¶
func (ts TestSuite) RunHandlerTests(t *testing.T, tests []HandlerTest)
RunHandlerTests runs all the HandlerTests inside a testing.T.Run() loop