Documentation ¶
Index ¶
- Constants
- Variables
- func DeRef(field interface{}) deref
- func RemoveInterfacePointer[T any](pointerInterface interface{}) interface{}
- func SimpleCookie(name, value string) *http.Cookie
- type GinData
- type GinDataInterface
- type MockReadCloser
- type TestConfig
- type TestOptions
- func (to *TestOptions[C, M, D]) Append(otherTestOptions ...*TestOptions[C, M, D]) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Checkout(tag string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Copy() *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) CreateFunctionTest(function interface{}, testName string) *TestConfig[C, M, D]
- func (to *TestOptions[C, M, D]) CreateMethodTest(method, testName string) *TestConfig[C, M, D]
- func (to *TestOptions[C, M, D]) CreateTest(testName string, getTestFunction func(state *TestState[C, M, D]) interface{}) *TestConfig[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputBody(value interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputBody_C(f func() []interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputBody_P(valuePointer interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputBody_SC(f func(state *TestState[C, M, D]) []interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputCookie(cookie *http.Cookie) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputCookie_C(callbackFunction func() *http.Cookie) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputCookie_SC(callbackFunction func(state *TestState[C, M, D]) *http.Cookie) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputCookies(cookies []*http.Cookie) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputCookies_C(cookiesFunction func() []*http.Cookie) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputCookies_SC(cookiesFunction func(state *TestState[C, M, D]) []*http.Cookie) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputCtx(key string, value interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputCtx_C(key string, callbackFunction func() interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputCtx_P(key string, valuePointer interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputCtx_SC(key string, callbackFunction func(state *TestState[C, M, D]) interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputHeader(key string, value interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputHeader_C(key string, callbackFunction func() string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputHeader_P(key string, value *string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputHeader_SC(key string, callbackFunction func(state *TestState[C, M, D]) string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputHeaders(headers map[string]interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputHeaders_C(key string, valueFunction func() string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputHeaders_P(headers map[string]*string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputHeaders_SC(headersFunction func(state *TestState[C, M, D]) map[string]interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputMethodAndURL(method, url interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputMethodAndURL_C(callbackFunction func() (method, url string)) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputMethodAndURL_P(method, url *string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputMethodAndURL_SC(callbackFunction func(state *TestState[C, M, D]) (method, url string)) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputParam(key string, value interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputParam_C(key string, valueFunction func() string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputParam_P(key string, value *string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputParam_SC(key string, valueFunction func(state *TestState[C, M, D]) string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputQuery(key string, value interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputQuery_C(key string, callbackFunction func() string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputQuery_P(key string, value *string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_InputQuery_SC(key string, callbackFunction func(state *TestState[C, M, D]) string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_OutputBody(expectedBody interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_OutputBody_C(callbackFunction func(state *TestState[C, M, D]) interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_OutputBody_P(expectedBodyPointer interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_OutputBody_SC(callbackFunction func(state *TestState[C, M, D]) interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_OutputCode(code interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_OutputCode_C(callbackFunction func() int) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_OutputCode_P(codePointer *int) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_OutputCode_SC(callbackFunction func(state *TestState[C, M, D]) int) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_OutputCookies(expectedCookies []*http.Cookie) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_OutputCookies_C(callbackFunction func() []*http.Cookie) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Gin_OutputCookies_SC(callbackFunction func(state *TestState[C, M, D]) []*http.Cookie) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Mock(mockChainFunction interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) NewOption(priority int, applyFunction func(state *TestState[C, M, D])) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Output(outputIndex int, expectedValue interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Output_C(outputIndex int, callbackFunction func() interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Output_P(outputIndex int, expectedValue *interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Output_SC(outputIndex int, callbackFunction func(state *TestState[C, M, D]) interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Outputs(expectedValues ...interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Outputs_C(callbackFunction func() []interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Outputs_P(expectedValues ...interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Outputs_SC(callbackFunction func(state *TestState[C, M, D]) []interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Prepare(prepareFunction func()) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Prepare_D(prepareFunction func(data *D)) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Prepare_S(prepareFunction func(state *TestState[C, M, D])) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) RegisterFunctionTest(function interface{}, testName string) *TestConfig[C, M, D]
- func (to *TestOptions[C, M, D]) RegisterMethodTest(method, testName string) *TestConfig[C, M, D]
- func (to *TestOptions[C, M, D]) RegisterTest(testName string, getTestFunction func(state *TestState[C, M, D]) interface{}) *TestConfig[C, M, D]
- func (to *TestOptions[C, M, D]) Repeat(count int) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) RepeatLast(count int) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) RepeatLastN(count int, n int) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) SetInput(argIndex int, value interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) SetInput_C(argIndex int, callbackFunction func() interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) SetInput_P(argIndex int, value interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) SetInput_SC(argIndex int, callbackFunction func(state *TestState[C, M, D]) interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) SetInputs(values ...interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) SetInputs_C(callbackFunction func() []interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) SetInputs_P(values ...interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) SetInputs_SC(callbackFunction func(state *TestState[C, M, D]) []interface{}) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Tag(tag string) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) Validate(f func(state *TestState[C, M, D]) error) *TestOptions[C, M, D]
- func (to *TestOptions[C, M, D]) WithPriority(priority int) *TestOptions[C, M, D]
- type TestState
- type Tester
- func NewFunctionTester[D any](initDataFunction func() *D) *Tester[interface{}, interface{}, D]
- func NewFunctionTesterWithoutData() *Tester[interface{}, interface{}, interface{}]
- func NewGinTester[C, M, D any](buildMocksFunction func(*testing.T) (C, *M), initDataFunction func() *D) *Tester[C, M, D]
- func NewTesterWithData[C, M, D any](buildMocksFunction func(*testing.T) (C, *M), initDataFunction func() *D) *Tester[C, M, D]
- func NewTesterWithInit[C, M any](buildMocksFunction func(*testing.T) (C, *M), initDataFunction func()) *Tester[C, M, interface{}]
- func NewTesterWithoutInit[C, M any](buildMocksFunction func(*testing.T) (C, *M)) *Tester[C, M, interface{}]
- func (tester *Tester[C, M, D]) Checkout(tag string) *TestOptions[C, M, D]
- func (tester *Tester[C, M, D]) NewOptions() *TestOptions[C, M, D]
- func (tester *Tester[C, M, D]) RegisterTests(tests ...*TestConfig[C, M, D]) *Tester[C, M, D]
- func (tester *Tester[C, M, D]) Test(t *testing.T)
- func (tester *Tester[C, M, D]) WithGroupID(groupID string) *Tester[C, M, D]
Constants ¶
const Empty = "__tests.empty__"
const Ignore = mock.Anything
Causes an output to be ignore
const Skip = "__tests.skip__"
Causes an input or output to be ignored when being set
Variables ¶
var DefaultInputPriority = -10
var DefaultMockPriority = -20
var DefaultOutputPriority = 10
var DefaultPreparePriority = -30
var DefaultSetupPriority = -50
var InitGinData = func() *GinData { data := &GinData{} return data }
Meant to be used with tests.NewGinTester. You can create your own if you'd like, just ensure the data type that is returned conforms to GinDataInterface
Functions ¶
func DeRef ¶ added in v1.2.0
func DeRef(field interface{}) deref
Deref should be used inside of functions that have "Supports DeRef()" written in their docstring somewhere. It allows you to pass in a pointer to something that you would like to be evaluated during the test, not before.
func RemoveInterfacePointer ¶ added in v1.1.0
func RemoveInterfacePointer[T any](pointerInterface interface{}) interface{}
Exposed interface pointer removal that requires the type to be passed into a generic function so a default value can be created in the zero case.
func SimpleCookie ¶ added in v1.0.0
Create a basic cookie with a name and a value. Shortcut for creating a cookie like this:
&http.Cookie{ Name: name, Value: value, }
Types ¶
type GinData ¶
Simple GIN context intialization
func (*GinData) GetRecorder ¶
func (d *GinData) GetRecorder() *httptest.ResponseRecorder
func (*GinData) PrepareForTest ¶
func (d *GinData) PrepareForTest()
type GinDataInterface ¶
type GinDataInterface interface { // Fetch the test context GetCtx() *gin.Context // Fetch the test engine GetEngine() *gin.Engine // Fetch the test response recorder GetRecorder() *httptest.ResponseRecorder /* Initialize the context, engine, and recorder. Is automatically called by the tester if using the NewGinTester() function. */ PrepareForTest() }
type MockReadCloser ¶ added in v1.2.0
func NewDefaultMockReadCloser ¶ added in v1.2.0
func NewDefaultMockReadCloser() *MockReadCloser
Creates a tests.MockReadCloser object with default read and close errors. These errors can be modified by accessing the ReadErr and CloseErr values.
func (*MockReadCloser) Close ¶ added in v1.2.0
func (e *MockReadCloser) Close() error
type TestConfig ¶
type TestConfig[C, M, D any] struct { Options *TestOptions[C, M, D] // contains filtered or unexported fields }
Individual test to be run by a tester. This is the interface which all children test types must conform to.
func (*TestConfig[C, M, D]) Register ¶ added in v1.1.0
func (tc *TestConfig[C, M, D]) Register(tester *Tester[C, M, D]) *TestConfig[C, M, D]
Helper function for adding a test to a tester. Makes it easier to do this inline
type TestOptions ¶
type TestOptions[C, M, D any] struct { // contains filtered or unexported fields }
The TestOptions object is responsible for providing bindings to all the test options available. It implements method chaining in order to make for a more simple interface for creating these options.
Each chained option should return a completely new TestOptions struct so as to allow easily expandable test setups.
func NewOptions ¶ added in v1.1.0
func NewOptions[C, M, D any](tester *Tester[C, M, D]) *TestOptions[C, M, D]
Create a new TestOptions object based on the type of a given tester. That tester is then automatically set as the new TestOptions's tester for branching.
func (*TestOptions[C, M, D]) Append ¶ added in v0.2.0
func (to *TestOptions[C, M, D]) Append( otherTestOptions ...*TestOptions[C, M, D], ) *TestOptions[C, M, D]
Create a new TestOptions object with all the options combined.
func (*TestOptions[C, M, D]) Checkout ¶ added in v0.2.0
func (to *TestOptions[C, M, D]) Checkout( tag string, ) *TestOptions[C, M, D]
Checkout the tagged TestOptions branch.
Once a tag is applied, you can fetch it: from any child TestOptions by: testOptions.Checkout($tagName) or from the parent tester by: tester.Checkout($tagName)
func (*TestOptions[C, M, D]) Copy ¶
func (to *TestOptions[C, M, D]) Copy() *TestOptions[C, M, D]
Create a shallow copy of test options.
func (*TestOptions[C, M, D]) CreateFunctionTest ¶
func (to *TestOptions[C, M, D]) CreateFunctionTest(function interface{}, testName string) *TestConfig[C, M, D]
Create a new test which automatically fetches the function given at runtime.
func (*TestOptions[C, M, D]) CreateMethodTest ¶
func (to *TestOptions[C, M, D]) CreateMethodTest(method, testName string) *TestConfig[C, M, D]
Create a new test which automatically fetches the named component method at runtime.
func (*TestOptions[C, M, D]) CreateTest ¶ added in v0.2.0
func (to *TestOptions[C, M, D]) CreateTest( testName string, getTestFunction func(state *TestState[C, M, D]) interface{}, ) *TestConfig[C, M, D]
Create a new test based on the given function. By doing things this way, private methods can be tested as well by accessing them from the state at runtime.
func (*TestOptions[C, M, D]) Gin_InputBody ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputBody( value interface{}, ) *TestOptions[C, M, D]
Set the body to the provided value. Has Priority = tests.DefaultInputPriority Supports DeRef()
func (*TestOptions[C, M, D]) Gin_InputBody_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputBody_C( f func() []interface{}, ) *TestOptions[C, M, D]
Set the body to the provided value based on a provided callback that calculates that value when this option is reached. Supports DeRef()
func (*TestOptions[C, M, D]) Gin_InputBody_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputBody_P( valuePointer interface{}, ) *TestOptions[C, M, D]
Set a pointer to the value the body shoudl take during the test. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputBody_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputBody_SC( f func(state *TestState[C, M, D]) []interface{}, ) *TestOptions[C, M, D]
Set the body to the provided value based on a provided callback that calculates that value based on the value of the TestState when this option is reached. Supports DeRef()
func (*TestOptions[C, M, D]) Gin_InputCookie ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputCookie( cookie *http.Cookie, ) *TestOptions[C, M, D]
Add a single cookie to the request. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputCookie_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputCookie_C( callbackFunction func() *http.Cookie, ) *TestOptions[C, M, D]
Add a single cookie to the request based on a provided callback that calculates that value when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputCookie_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputCookie_SC( callbackFunction func(state *TestState[C, M, D]) *http.Cookie, ) *TestOptions[C, M, D]
Add a single cookie to the request based on a provided callback that calculates that value based on the value of the TestState when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputCookies ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputCookies( cookies []*http.Cookie, ) *TestOptions[C, M, D]
Adds many cookies to the request. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputCookies_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputCookies_C( cookiesFunction func() []*http.Cookie, ) *TestOptions[C, M, D]
Adds many cookies to the request based on a provided callback that calculates that value when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputCookies_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputCookies_SC( cookiesFunction func(state *TestState[C, M, D]) []*http.Cookie, ) *TestOptions[C, M, D]
Adds many cookies to the request based on a provided callback that calculates that value based on the value of the TestState when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputCtx ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputCtx( key string, value interface{}, ) *TestOptions[C, M, D]
Sets a specific key-value pair in the gin context prior to execution. Has Priority = tests.DefaultInputPriority Supports DeRef()
func (*TestOptions[C, M, D]) Gin_InputCtx_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputCtx_C( key string, callbackFunction func() interface{}, ) *TestOptions[C, M, D]
Sets a gin ctx key-value pair based on a provided callback that calculates that value when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputCtx_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputCtx_P( key string, valuePointer interface{}, ) *TestOptions[C, M, D]
Specify a key and a pointer to a value for a key-value pair in the gin context prior to execution. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputCtx_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputCtx_SC( key string, callbackFunction func(state *TestState[C, M, D]) interface{}, ) *TestOptions[C, M, D]
Sets a gin ctx key-value pair based on a provided callback that calculates that value based on the value of the TestState when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputHeader ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputHeader( key string, value interface{}, ) *TestOptions[C, M, D]
Write a header value. Has Priority = tests.DefaultInputPriority value arg Supports DeRef()
func (*TestOptions[C, M, D]) Gin_InputHeader_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputHeader_C( key string, callbackFunction func() string, ) *TestOptions[C, M, D]
Write a header value based on a provided callback that calculates that value when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputHeader_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputHeader_P( key string, value *string, ) *TestOptions[C, M, D]
Write a header value. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputHeader_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputHeader_SC( key string, callbackFunction func(state *TestState[C, M, D]) string, ) *TestOptions[C, M, D]
Write a header value based on a provided callback that calculates that value based on the value of the TestState when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputHeaders ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputHeaders( headers map[string]interface{}, ) *TestOptions[C, M, D]
Write header values. Has Priority = tests.DefaultInputPriority map value args Supports DeRef()
func (*TestOptions[C, M, D]) Gin_InputHeaders_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputHeaders_C( key string, valueFunction func() string, ) *TestOptions[C, M, D]
Write header values based on a provided callback that calculates that value when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputHeaders_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputHeaders_P( headers map[string]*string, ) *TestOptions[C, M, D]
Write header values where the values are all pointers. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputHeaders_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputHeaders_SC( headersFunction func(state *TestState[C, M, D]) map[string]interface{}, ) *TestOptions[C, M, D]
Write header values based on a provided callback that calculates that value based on the value of the TestState when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputMethodAndURL ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputMethodAndURL( method, url interface{}, ) *TestOptions[C, M, D]
Set the method and URL for a particular test. If net/url.Parse(url) would cause an error, this will panic. This will also panic if the method and url are not string types. Has Priority = tests.DefaultSetupPriority Supports DeRef()
func (*TestOptions[C, M, D]) Gin_InputMethodAndURL_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputMethodAndURL_C( callbackFunction func() (method, url string), ) *TestOptions[C, M, D]
Set the method and URL for a particular test based on a provided callback that calculates those values when this option is reached. If net/url.Parse(url) would cause an error, this will panic. Has Priority = tests.DefaultSetupPriority
func (*TestOptions[C, M, D]) Gin_InputMethodAndURL_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputMethodAndURL_P( method, url *string, ) *TestOptions[C, M, D]
Specify pointers to the method and URL for a particular test. If net/url.Parse(url) would cause an error, this will panic. Has Priority = tests.DefaultSetupPriority
func (*TestOptions[C, M, D]) Gin_InputMethodAndURL_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputMethodAndURL_SC( callbackFunction func(state *TestState[C, M, D]) (method, url string), ) *TestOptions[C, M, D]
Set the method and URL for a particular test based on a provided callback that calculates those values based on the value of the TestState when this option is reached. If net/url.Parse(url) would cause an error, this will panic. Has Priority = tests.DefaultSetupPriority
func (*TestOptions[C, M, D]) Gin_InputParam ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputParam( key string, value interface{}, ) *TestOptions[C, M, D]
Set a specific key-value pair in params. Has Priority = tests.DefaultInputPriority value arg Supports DeRef()
func (*TestOptions[C, M, D]) Gin_InputParam_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputParam_C( key string, valueFunction func() string, ) *TestOptions[C, M, D]
Set a specific key-value pair in params based on a provided callback that calculates that value when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputParam_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputParam_P( key string, value *string, ) *TestOptions[C, M, D]
Set a specific key and a pointer to its value in params Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputParam_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputParam_SC( key string, valueFunction func(state *TestState[C, M, D]) string, ) *TestOptions[C, M, D]
Set a specific key-value pair in params based on a provided callback that calculates that value based on the value of the TestState when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputQuery ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputQuery( key string, value interface{}, ) *TestOptions[C, M, D]
Directly specify a key-value pair to be included the request query string. Has Priority = tests.DefaultInputPriority value arg Supports DeRef()
func (*TestOptions[C, M, D]) Gin_InputQuery_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputQuery_C( key string, callbackFunction func() string, ) *TestOptions[C, M, D]
Specify a key-value pair to be included the request query string based on a provided callback that calculates that value when this option is reached.
func (*TestOptions[C, M, D]) Gin_InputQuery_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputQuery_P( key string, value *string, ) *TestOptions[C, M, D]
Specify a pointer to a key and value of a key-value pair to be included the request query string. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Gin_InputQuery_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_InputQuery_SC( key string, callbackFunction func(state *TestState[C, M, D]) string, ) *TestOptions[C, M, D]
Specify a key-value pair to be included the request query string based on a provided callback that calculates that value based on the value of the TestState when this option is reached.
func (*TestOptions[C, M, D]) Gin_OutputBody ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_OutputBody( expectedBody interface{}, ) *TestOptions[C, M, D]
Ensures the body of the recorder matches the data passed in. Has Priority = tests.DefaultOutputPriority Supports DeRef()
func (*TestOptions[C, M, D]) Gin_OutputBody_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_OutputBody_C( callbackFunction func(state *TestState[C, M, D]) interface{}, ) *TestOptions[C, M, D]
Ensures the body of the recorder matches the data passed in based on a provided callback that calculates that value when this option is reached. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Gin_OutputBody_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_OutputBody_P( expectedBodyPointer interface{}, ) *TestOptions[C, M, D]
Ensures the body of the recorder matches the data pointed to. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Gin_OutputBody_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_OutputBody_SC( callbackFunction func(state *TestState[C, M, D]) interface{}, ) *TestOptions[C, M, D]
Ensures the body of the recorder matches the data passed in based on a provided callback that calculates that value based on the value of the TestState when this option is reached. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Gin_OutputCode ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_OutputCode( code interface{}, ) *TestOptions[C, M, D]
Ensures the http code that's written to the recorder matches the provided code Has Priority = tests.DefaultOutputPriority Supports DeRef()
func (*TestOptions[C, M, D]) Gin_OutputCode_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_OutputCode_C( callbackFunction func() int, ) *TestOptions[C, M, D]
Ensures the http code that's written to the recorder matches based on a provided callback that calculates that value when this option is reached. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Gin_OutputCode_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_OutputCode_P( codePointer *int, ) *TestOptions[C, M, D]
Ensures the http code that's written to the recorder matches the code that is pointed to. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Gin_OutputCode_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_OutputCode_SC( callbackFunction func(state *TestState[C, M, D]) int, ) *TestOptions[C, M, D]
Ensures the http code that's written to the recorder matches based on a provided callback that calculates that value based on the value of the TestState when this option is reached. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Gin_OutputCookies ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_OutputCookies( expectedCookies []*http.Cookie, ) *TestOptions[C, M, D]
Ensures all cookies that are written to the recorder match all provided cookies. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Gin_OutputCookies_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_OutputCookies_C( callbackFunction func() []*http.Cookie, ) *TestOptions[C, M, D]
Ensures all cookies that are written to the recorder match all provided cookies based on a provided callback that calculates that value when this option is reached. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Gin_OutputCookies_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Gin_OutputCookies_SC( callbackFunction func(state *TestState[C, M, D]) []*http.Cookie, ) *TestOptions[C, M, D]
Ensures all cookies that are written to the recorder match all provided cookies based on a provided callback that calculates that value based on the value of the TestState when this option is reached. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Mock ¶ added in v1.0.0
func (to *TestOptions[C, M, D]) Mock( mockChainFunction interface{}, ) *TestOptions[C, M, D]
Function to automatically handle a mock chain. Use the autogenerated functions from the components command placed at the bottom of your component definition file, prefixed with "mock_" to use this.
ex. mock_component().$Method(args...).Return(response...) (or similar)
Has Priority = tests.DefaultMockPriority
func (*TestOptions[C, M, D]) NewOption ¶
func (to *TestOptions[C, M, D]) NewOption( priority int, applyFunction func(state *TestState[C, M, D]), ) *TestOptions[C, M, D]
General use case for adding an option. If there is any arbitrary thing you need to do, and the premade functions do not allow you to do it, you can add a generic option to allow you to do anything. It sends the whole state of the test into the "applyFunction" for you to modify as you please.
func (*TestOptions[C, M, D]) Output ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Output( outputIndex int, expectedValue interface{}, ) *TestOptions[C, M, D]
Directly specify the expected value of an output at a given index. Has Priority = tests.DefaultOutputPriority Supports DeRef()
func (*TestOptions[C, M, D]) Output_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Output_C( outputIndex int, callbackFunction func() interface{}, ) *TestOptions[C, M, D]
Specify the expected value of an output at a given index based on a provided function that calculates that value when this option is reached. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Output_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Output_P( outputIndex int, expectedValue *interface{}, ) *TestOptions[C, M, D]
Specify a pointer to the expected value of an output at a given index. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Output_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Output_SC( outputIndex int, callbackFunction func(state *TestState[C, M, D]) interface{}, ) *TestOptions[C, M, D]
Specify the expected value of an output at a given index based on a provided function that calculates that value based on the value of the TestState when this option is reached. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Outputs ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Outputs( expectedValues ...interface{}, ) *TestOptions[C, M, D]
Directly specify the expected value of all outputs at once. Has Priority = tests.DefaultOutputPriority Supports DeRef()
func (*TestOptions[C, M, D]) Outputs_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Outputs_C( callbackFunction func() []interface{}, ) *TestOptions[C, M, D]
Specify the expected values of all outputs at once based on a provided callback that calculates that value when this option is reached. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Outputs_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Outputs_P( expectedValues ...interface{}, ) *TestOptions[C, M, D]
Specify pointers to the expected values of all outputs at once. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Outputs_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Outputs_SC( callbackFunction func(state *TestState[C, M, D]) []interface{}, ) *TestOptions[C, M, D]
Specify the expected values of all outputs at once based on a provided callback that calculates that value based on the value of the TestState when this option is reached. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) Prepare ¶ added in v1.1.0
func (to *TestOptions[C, M, D]) Prepare( prepareFunction func(), ) *TestOptions[C, M, D]
Perform some generic action. Has Priority = tests.DefaultPreparePriority
func (*TestOptions[C, M, D]) Prepare_D ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Prepare_D( prepareFunction func(data *D), ) *TestOptions[C, M, D]
Prepare some action dependant on the data in the internal TestState. Has Priority = tests.DefaultPreparePriority
func (*TestOptions[C, M, D]) Prepare_S ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Prepare_S( prepareFunction func(state *TestState[C, M, D]), ) *TestOptions[C, M, D]
Prepare some action dependant on the entirety of the internal TestState. Has Priority = tests.DefaultPreparePriority
func (*TestOptions[C, M, D]) RegisterFunctionTest ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) RegisterFunctionTest(function interface{}, testName string) *TestConfig[C, M, D]
Create and register a new test which automatically fetches the function given at runtime.
func (*TestOptions[C, M, D]) RegisterMethodTest ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) RegisterMethodTest(method, testName string) *TestConfig[C, M, D]
Create and register a new test which automatically fetches the named component method at runtime.
func (*TestOptions[C, M, D]) RegisterTest ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) RegisterTest( testName string, getTestFunction func(state *TestState[C, M, D]) interface{}, ) *TestConfig[C, M, D]
Create and register a new test based on the given function.
func (*TestOptions[C, M, D]) Repeat ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) Repeat(count int) *TestOptions[C, M, D]
Repeat all the options in this TestOptions "count" times
func (*TestOptions[C, M, D]) RepeatLast ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) RepeatLast(count int) *TestOptions[C, M, D]
Repeat the last option added to TestOptions "count" times
func (*TestOptions[C, M, D]) RepeatLastN ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) RepeatLastN(count int, n int) *TestOptions[C, M, D]
Repeat the last "n" options added to TestOptions "count" times
func (*TestOptions[C, M, D]) SetInput ¶
func (to *TestOptions[C, M, D]) SetInput( argIndex int, value interface{}, ) *TestOptions[C, M, D]
Directly specify the value of a particular arg. Has Priority = tests.DefaultInputPriority Supports DeRef()
func (*TestOptions[C, M, D]) SetInput_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) SetInput_C( argIndex int, callbackFunction func() interface{}, ) *TestOptions[C, M, D]
Specify a value of a particular arg based on a provided callback that calculates that value when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) SetInput_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) SetInput_P( argIndex int, value interface{}, ) *TestOptions[C, M, D]
Specify the pointer to the value of a particular arg. If the input expects the type "int", you would pass in "*int". Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) SetInput_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) SetInput_SC( argIndex int, callbackFunction func(state *TestState[C, M, D]) interface{}, ) *TestOptions[C, M, D]
Specify a value of a particular arg based on a provided callback that calculates that value based on the value of the TestState when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) SetInputs ¶
func (to *TestOptions[C, M, D]) SetInputs( values ...interface{}, ) *TestOptions[C, M, D]
Directly specify the value of all args at once. To skip setting a particular arg, set it to tests.Skip Has Priority = tests.DefaultInputPriority Supports DeRef()
func (*TestOptions[C, M, D]) SetInputs_C ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) SetInputs_C( callbackFunction func() []interface{}, ) *TestOptions[C, M, D]
Specify all args valuesbased on a provided callback that calculates those values when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) SetInputs_P ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) SetInputs_P( values ...interface{}, ) *TestOptions[C, M, D]
Specify the pointer to all arg values at once. To skip setting a particular arg, set it to tests.Skip Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) SetInputs_SC ¶ added in v1.2.0
func (to *TestOptions[C, M, D]) SetInputs_SC( callbackFunction func(state *TestState[C, M, D]) []interface{}, ) *TestOptions[C, M, D]
Specify all args valuesbased on a provided callback that calculates those values based on the value of the TestState when this option is reached. Has Priority = tests.DefaultInputPriority
func (*TestOptions[C, M, D]) Tag ¶ added in v0.2.0
func (to *TestOptions[C, M, D]) Tag( tag string, ) *TestOptions[C, M, D]
Create a tag which allows options to be "checked-out" later.
Once a tag is applied, you can fetch it: from any child TestOptions by: testOptions.Checkout($tagName) or from the parent tester by: tester.Checkout($tagName)
func (*TestOptions[C, M, D]) Validate ¶ added in v1.1.0
func (to *TestOptions[C, M, D]) Validate( f func(state *TestState[C, M, D]) error, ) *TestOptions[C, M, D]
After the test has run, check something arbitrary about the test state. If the provided callback returns an error, the test will fail. Has Priority = tests.DefaultOutputPriority
func (*TestOptions[C, M, D]) WithPriority ¶
func (to *TestOptions[C, M, D]) WithPriority(priority int) *TestOptions[C, M, D]
Adjusts the priority of the last option in the TestOptions. If no options exist currently, will panic so that the method chaining archetype can be preserved. Priorities < 0 are run before the test runs Priorities > 0 are run after test runs Priority = 0 is reserved for state cleanup before checking outputs Lower value priority occurs first.
type TestState ¶
type TestState[C, M, D any] struct { Assertions *assert.Assertions Component C Mocks *M Data *D Input []interface{} Output []interface{} }
The internal test state. Is automatically updated as options are called.
type Tester ¶
type Tester[C, M, D any] struct { // Global options for this tester Options *TestOptions[C, M, D] /* Whether or not the tester should run tests in parallel. This is not recommended unless you are utilizing test data. */ Parallel bool // contains filtered or unexported fields }
A tester is the base unit that handles mock testing for a component. Type C is the base component type Type M is the component mocks type Type D is the data type.
func NewFunctionTester ¶
Create a new Tester for a function or a group of functions. This does not require any components or mocks to run as it is intended to be used on individual functions. The rest of the tester suite can still be used in this case, although the inferred generic types for the C (Component) and M (Mocks) fields will both simply be interfaces. You should ignore those fields in the Options.
func NewFunctionTesterWithoutData ¶ added in v1.2.0
func NewFunctionTesterWithoutData() *Tester[interface{}, interface{}, interface{}]
Create a new Tester for a function or a group of functions. This does not require any components or mocks to run as it is intended to be used on individual functions. The rest of the tester suite can still be used in this case, although the inferred generic types for the C (Component) and M (Mocks) fields will both simply be interfaces. You should ignore those fields in the Options.
func NewGinTester ¶
func NewGinTester[C, M, D any]( buildMocksFunction func(*testing.T) (C, *M), initDataFunction func() *D, ) *Tester[C, M, D]
Create a new Tester for methods requiring a gin test context. You may use tests.InitGinData as the initDataFunction for convenience. Otherwise, the custom data structure provided must conform to the interface tests.GinDataInterface or else your test will panic. You may compose the tests.GinData into your data object to get this automatically.
This will automatically attach 2 options to the returned tester.Options:
Test Prep at priority tests.DefaultSetupPriority: This casts the data to GinDataInterface and calls GinDataInterface.PrepareForTest(). This sets up the test recorder, context, and engine for the gin tester.
Output Prep at priority 0 (just before the test runs): This casts the input at arg index 0 to a gin context.
func NewTesterWithData ¶ added in v1.2.0
func NewTesterWithData[C, M, D any]( buildMocksFunction func(*testing.T) (C, *M), initDataFunction func() *D, ) *Tester[C, M, D]
Create a new Tester with a specified Component, Mocks, and Data structure.
func NewTesterWithInit ¶ added in v1.1.0
func NewTesterWithInit[C, M any]( buildMocksFunction func(*testing.T) (C, *M), initDataFunction func(), ) *Tester[C, M, interface{}]
Create a new Tester with a specified Component and Mocks structure. Requires a provided initialization function.
func NewTesterWithoutInit ¶ added in v1.2.0
func NewTesterWithoutInit[C, M any]( buildMocksFunction func(*testing.T) (C, *M), ) *Tester[C, M, interface{}]
Create a new Tester with a specified Component and Mocks structure. No initialization step is called for this kind of tester. The inferred type for the data is interface{}, but it will always be set to nil for tests created this way.
func (*Tester[C, M, D]) Checkout ¶ added in v1.2.0
func (tester *Tester[C, M, D]) Checkout( tag string, ) *TestOptions[C, M, D]
Checkout the tagged TestOptions branch.
Once a tag is applied, you can fetch it: from any child TestOptions by: testOptions.Checkout($tagName) or from the parent tester by: tester.Checkout($tagName)
func (*Tester[C, M, D]) NewOptions ¶ added in v1.0.0
func (tester *Tester[C, M, D]) NewOptions() *TestOptions[C, M, D]
Create a new options for this tester without any of the existing options included. Makes it slightly easier to create branches.
func (*Tester[C, M, D]) RegisterTests ¶ added in v1.2.0
func (tester *Tester[C, M, D]) RegisterTests( tests ...*TestConfig[C, M, D], ) *Tester[C, M, D]
Register tests with the tester. All registered tests will be run when tester.Test(t) is called
func (*Tester[C, M, D]) Test ¶
Runs all the currently appended tests in the order in which they were appended.
func (*Tester[C, M, D]) WithGroupID ¶
Attach a group id to the tester so that all test names under this tester automatically have a prefix attached to them.