Documentation
¶
Overview ¶
Package testingtools provides test helpers and mock infrastructure for requestCore.
Index ¶
- Constants
- func DefaultAPIList() map[string]libCallApi.RemoteAPI
- func DefaultAccessRoles() map[string]string
- func DefaultDB(t *testing.T) *sql.DB
- func DefaultErrorDesc() map[string]string
- func GetAllSimulationHandler[Req any](core requestCore.RequestCoreInterface) gin.HandlerFunc
- func GetDMLModel(t *testing.T, m Model) libQuery.QueryRunnerModel
- func GetEnv[Env any, PT interface{ ... }](t *testing.T, defaultAPIList func() map[string]libCallApi.RemoteAPI) PT
- func GetEnvWithDB[Env any, PT interface{ ... }](db *sql.DB, defaultAPIList func() map[string]libCallApi.RemoteAPI) PT
- func GetRequestModel(t *testing.T) libQuery.QueryRunnerModel
- func GetSelectModel(t *testing.T, m Model) libQuery.QueryRunnerModel
- func GetSingleSimulationHandler[Req any](core requestCore.RequestCoreInterface) gin.HandlerFunc
- func InitSimulationHandler[Req any](c context.Context, core requestCore.RequestCoreInterface) (*Req, error)
- func InitTesting(t *testing.T, errDesc map[string]string, ...) (requestCore.RequestCoreModel, libParams.ParamInterface)
- func InitTestingNoDB(t *testing.T, errDesc map[string]string, ...) (requestCore.RequestCoreModel, libParams.ParamInterface)
- func InitTestingWithDB(errDesc map[string]string, remoteApis map[string]libCallApi.RemoteAPI, ...) (requestCore.RequestCoreModel, libParams.ApplicationParams[TestingParams])
- func PrepareEnvWithDB(env TestingEnv, db *sql.DB)
- func SampleMockDB(t *testing.T, mockList func(sqlmock.Sqlmock)) *sql.DB
- func SampleQueryMock(t *testing.T, mockList func(sqlmock.Sqlmock)) libQuery.QueryRunnerModel
- func SampleRequestModelMock(t *testing.T, mockList func(sqlmock.Sqlmock)) libQuery.QueryRunnerModel
- func TestAPI(t *testing.T, testCases []TestCase, options *TestOptions)
- func TestAPIList() map[string]libCallApi.RemoteAPI
- func TestDB(t *testing.T, tc *TestCase, options *TestOptions)
- func TestDBFiber(t *testing.T, tc *TestCase, options *TestOptions)
- func TestDMLs[Model any, PT interface{ ... }](t *testing.T)
- func TestFetchData[Model any, PT interface{ ... }](t *testing.T, queryList map[string]libQuery.QueryCommand)
- type AnyString
- type CustomMockConverter
- type Header
- type KeyValuePair
- type Model
- type TestCase
- type TestEnv
- type TestOptions
- type TestingEnv
- type TestingParams
- type TestingWsParams
- func (p *TestingWsParams) GetFonts() map[string]opentype.Font
- func (p *TestingWsParams) GetHeaderName() string
- func (p *TestingWsParams) GetImages() map[string]image.Image
- func (p *TestingWsParams) GetLogCompress() bool
- func (p *TestingWsParams) GetLogPath() string
- func (p *TestingWsParams) GetLogSize() int
- func (p *TestingWsParams) GetParams() map[string]string
- func (p *TestingWsParams) GetRoles() map[string]string
- func (p *TestingWsParams) GetSkipPaths() []string
Constants ¶
const Default = "default"
Default is the constant key for the default test configuration.
Variables ¶
This section is empty.
Functions ¶
func DefaultAPIList ¶
func DefaultAPIList() map[string]libCallApi.RemoteAPI
DefaultAPIList returns a default map of remote API configurations for testing.
func DefaultAccessRoles ¶
DefaultAccessRoles returns a default access-role map for testing.
func DefaultErrorDesc ¶
DefaultErrorDesc returns a default error-description map for testing.
func GetAllSimulationHandler ¶
func GetAllSimulationHandler[Req any](core requestCore.RequestCoreInterface) gin.HandlerFunc
GetAllSimulationHandler returns a gin handler that parses and responds with a list of simulation requests.
func GetDMLModel ¶
func GetDMLModel(t *testing.T, m Model) libQuery.QueryRunnerModel
GetDMLModel handles INSERT, UPDATE, and DELETE in mock DB models.
func GetEnv ¶
func GetEnv[Env any, PT interface { GetInterface() requestCore.RequestCoreInterface GetParams() libParams.ParamInterface SetInterface(requestCore.RequestCoreInterface) SetParams(libParams.ParamInterface) *Env }](t *testing.T, defaultAPIList func() map[string]libCallApi.RemoteAPI) PT
GetEnv creates and initializes a typed test environment with a default mock database.
func GetEnvWithDB ¶
func GetEnvWithDB[Env any, PT interface { GetInterface() requestCore.RequestCoreInterface GetParams() libParams.ParamInterface SetInterface(requestCore.RequestCoreInterface) SetParams(libParams.ParamInterface) *Env }](db *sql.DB, defaultAPIList func() map[string]libCallApi.RemoteAPI) PT
GetEnvWithDB creates and initializes a typed test environment with the given database and API list.
func GetRequestModel ¶ added in v0.9.47
func GetRequestModel(t *testing.T) libQuery.QueryRunnerModel
GetRequestModel returns a QueryRunnerModel backed by a sqlmock database with predefined query expectations.
func GetSelectModel ¶
func GetSelectModel(t *testing.T, m Model) libQuery.QueryRunnerModel
GetSelectModel handles selecting a single or all items in mock DB model.
func GetSingleSimulationHandler ¶
func GetSingleSimulationHandler[Req any](core requestCore.RequestCoreInterface) gin.HandlerFunc
GetSingleSimulationHandler returns a gin handler that parses and responds with a single simulation request.
func InitSimulationHandler ¶
func InitSimulationHandler[Req any](c context.Context, core requestCore.RequestCoreInterface) (*Req, error)
InitSimulationHandler parses a simulation request from the context and returns the typed request body.
func InitTesting ¶
func InitTesting(t *testing.T, errDesc map[string]string, remoteApis map[string]libCallApi.RemoteAPI, query string, columns []string, csv string, module string, ) (requestCore.RequestCoreModel, libParams.ParamInterface)
InitTesting initializes the test server with the given parameters and returns the request core model and parameter interface.
func InitTestingNoDB ¶
func InitTestingNoDB(t *testing.T, errDesc map[string]string, remoteApis map[string]libCallApi.RemoteAPI, ) (requestCore.RequestCoreModel, libParams.ParamInterface)
InitTestingNoDB initializes a test request-core model without a custom database, using a default mock DB.
func InitTestingWithDB ¶
func InitTestingWithDB( errDesc map[string]string, remoteApis map[string]libCallApi.RemoteAPI, db *sql.DB, ) (requestCore.RequestCoreModel, libParams.ApplicationParams[TestingParams])
InitTestingWithDB initializes a test request-core model with the given error descriptions, remote APIs, and database.
func PrepareEnvWithDB ¶ added in v0.9.47
func PrepareEnvWithDB(env TestingEnv, db *sql.DB)
PrepareEnvWithDB initializes a TestingEnv with default error descriptions, API list, and the given database.
func SampleMockDB ¶ added in v0.10.2
SampleMockDB returns a mock *sql.DB with optional custom mock expectations.
func SampleQueryMock ¶ added in v0.9.20
SampleQueryMock returns a QueryRunnerModel in mock mode with optional custom mock expectations.
func SampleRequestModelMock ¶
SampleRequestModelMock returns a QueryRunnerModel with predefined mock expectations for request handling.
func TestAPI ¶
func TestAPI(t *testing.T, testCases []TestCase, options *TestOptions)
TestAPI tests a group of Api's test.
func TestAPIList ¶ added in v0.9.7
func TestAPIList() map[string]libCallApi.RemoteAPI
TestAPIList returns a default map of remote API configurations for API testing.
func TestDB ¶
func TestDB(t *testing.T, tc *TestCase, options *TestOptions)
TestDB tests a single DB models.
func TestDBFiber ¶
func TestDBFiber(t *testing.T, tc *TestCase, options *TestOptions)
TestDBFiber tests a single DB model using the Fiber framework.
func TestDMLs ¶
TestDMLs tests a model for equality of commands arguments, and given argumants, also it checks if given type is the same is the command.
func TestFetchData ¶
func TestFetchData[Model any, PT interface { libQuery.QueryRequest *Model }](t *testing.T, queryList map[string]libQuery.QueryCommand)
TestFetchData tests query models for equality of command argument counts against provided arguments.
Types ¶
type AnyString ¶
type AnyString string
AnyString is a sqlmock argument type that matches any driver value.
type CustomMockConverter ¶ added in v0.9.55
type CustomMockConverter struct{}
CustomMockConverter is a sqlmock value converter that handles common Go types.
func (CustomMockConverter) ConvertValue ¶ added in v0.9.55
func (CustomMockConverter) ConvertValue(v interface{}) (driver.Value, error)
ConvertValue converts a Go value into a driver.Value for the mock database.
type Header ¶
type Header []KeyValuePair
Header is a slice of KeyValuePair used to set HTTP headers in test requests.
type KeyValuePair ¶
KeyValuePair holds a single key-value pair used for test headers.
type TestCase ¶
type TestCase struct {
Name string
URL string
Header Header
Model libQuery.QueryRunnerModel
Request any
Status int
CheckBody []string
CheckNotInBody []string
CheckHeader map[string]string
DontReadBody bool
MockError error
Desired any
DesiredError string
DesiredResp string
}
TestCase defines a single test case including URL, headers, expected status, and body checks.
type TestEnv ¶
type TestEnv struct {
Params libParams.ParamInterface
Interface requestCore.RequestCoreInterface
}
TestEnv holds the parameter and request-core interfaces for a test environment.
func (TestEnv) GetInterface ¶
func (env TestEnv) GetInterface() requestCore.RequestCoreInterface
GetInterface returns the request-core interface for the test environment.
func (TestEnv) GetParams ¶
func (env TestEnv) GetParams() libParams.ParamInterface
GetParams returns the parameter interface for the test environment.
func (*TestEnv) SetInterface ¶
func (env *TestEnv) SetInterface(core requestCore.RequestCoreInterface)
SetInterface sets the request-core interface for the test environment.
func (*TestEnv) SetParams ¶
func (env *TestEnv) SetParams(params libParams.ParamInterface)
SetParams sets the parameter interface for the test environment.
type TestOptions ¶
type TestOptions struct {
Path string
Name string
Method string
Handler any
Middleware gin.HandlerFunc
MiddlewareFiber fiber.Handler
Silent bool
}
TestOptions configures the test server including path, method, handler, and middleware.
type TestingEnv ¶ added in v0.9.47
type TestingEnv interface {
GetInterface() requestCore.RequestCoreInterface
GetParams() libParams.ParamInterface
SetInterface(requestCore.RequestCoreInterface)
SetParams(libParams.ParamInterface)
}
TestingEnv defines the interface for a test environment that holds request-core and parameter interfaces.
type TestingParams ¶ added in v0.16.0
type TestingParams struct {
}
TestingParams is the parameter type used for test application configuration.
type TestingWsParams ¶
type TestingWsParams struct {
RemoteAPIs map[string]libCallApi.RemoteAPI `yaml:"remoteApis"`
ErrorDesc map[string]string `yaml:"errorDesc"`
MessageDesc map[string]string `yaml:"messageDesc"`
AccessRoles map[string]string `yaml:"accessRoles"`
}
TestingWsParams holds remote API, error description, message description, and access role maps for testing.
func (*TestingWsParams) GetFonts ¶
func (p *TestingWsParams) GetFonts() map[string]opentype.Font
GetFonts returns the font map for the test environment (always nil in tests).
func (*TestingWsParams) GetHeaderName ¶
func (p *TestingWsParams) GetHeaderName() string
GetHeaderName returns the header name used for request identification in tests.
func (*TestingWsParams) GetImages ¶
func (p *TestingWsParams) GetImages() map[string]image.Image
GetImages returns the image map for the test environment (always nil in tests).
func (*TestingWsParams) GetLogCompress ¶
func (p *TestingWsParams) GetLogCompress() bool
GetLogCompress returns whether log files should be compressed in the test environment.
func (*TestingWsParams) GetLogPath ¶
func (p *TestingWsParams) GetLogPath() string
GetLogPath returns the log file path for the test environment.
func (*TestingWsParams) GetLogSize ¶
func (p *TestingWsParams) GetLogSize() int
GetLogSize returns the log rotation size in megabytes for the test environment.
func (*TestingWsParams) GetParams ¶
func (p *TestingWsParams) GetParams() map[string]string
GetParams returns the parameter map for the test environment (always nil in tests).
func (*TestingWsParams) GetRoles ¶
func (p *TestingWsParams) GetRoles() map[string]string
GetRoles returns the access role map for the test environment (always nil in tests).
func (*TestingWsParams) GetSkipPaths ¶
func (p *TestingWsParams) GetSkipPaths() []string
GetSkipPaths returns the paths to skip in access logging for the test environment.