gopitest

package
v0.0.0-...-86d5c46 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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

View Source
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.

View Source
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

type AssertFunc func(t *testing.T, v interface{})

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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