testingtools

package
v0.10.20 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultAPIList

func DefaultAPIList() map[string]libCallApi.RemoteApi

func DefaultAccessRoles

func DefaultAccessRoles() map[string]string

func DefaultDB

func DefaultDB(t *testing.T) *sql.DB

func DefaultErrorDesc

func DefaultErrorDesc() map[string]string

func GetAllSimulationHandler

func GetAllSimulationHandler[Req any](core requestCore.RequestCoreInterface) gin.HandlerFunc

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

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

func GetRequestModel added in v0.9.47

func GetRequestModel(t *testing.T) libQuery.QueryRunnerModel

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

func InitSimulationHandler

func InitSimulationHandler[Req any](c context.Context, core requestCore.RequestCoreInterface) (*Req, error)

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)

columns are prefixed with "o" since we used sqlstruct to generate them

func InitTestingNoDB

func InitTestingNoDB(t *testing.T,
	errDesc map[string]string,
	remoteApis map[string]libCallApi.RemoteApi,
) (requestCore.RequestCoreModel, libParams.ParamInterface)

func PrepareEnvWithDB added in v0.9.47

func PrepareEnvWithDB(env TestingEnv, db *sql.DB)

func SampleMockDB added in v0.10.2

func SampleMockDB(t *testing.T, mockList func(sqlmock.Sqlmock)) *sql.DB

func SampleQueryMock added in v0.9.20

func SampleQueryMock(t *testing.T, mockList func(sqlmock.Sqlmock)) libQuery.QueryRunnerModel

func SampleRequestModelMock

func SampleRequestModelMock(t *testing.T, mockList func(sqlmock.Sqlmock)) libQuery.QueryRunnerModel

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

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)

TestDB tests a single DB models.

func TestDMLs

func TestDMLs[Model any, PT interface {
	libQuery.DmlModel
	*Model
}](t *testing.T)

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)

Types

type AnyString

type AnyString string

func (AnyString) Match

func (a AnyString) Match(_ driver.Value) bool

Match satisfies sqlmock.Argument interface

type CustomMockConverter added in v0.9.55

type CustomMockConverter struct{}

func (CustomMockConverter) ConvertValue added in v0.9.55

func (CustomMockConverter) ConvertValue(v interface{}) (driver.Value, error)
type Header []KeyValuePair

func (Header) Map

func (h Header) Map() map[string][]string

Map converts a Header to a map.

type KeyValuePair

type KeyValuePair struct {
	Key   string
	Value string
}

type Model

type Model struct {
	Query   string
	Columns []string
	Values  [][]any
	Args    []any
	Err     error
}

type Params added in v0.9.47

type Params struct {
	Roles       map[string]string
	Params      map[string]string
	ErrorDesc   map[string]string
	MessageDesc map[string]string
	AccessRoles map[string]string
	RemoteApis  map[string]libCallApi.RemoteApi
}

func InitTestingWithDB

func InitTestingWithDB(
	errDesc map[string]string,
	remoteApis map[string]libCallApi.RemoteApi,
	db *sql.DB,
) (requestCore.RequestCoreModel, Params)

func (Params) GetFonts added in v0.9.47

func (p Params) GetFonts() map[string]opentype.Font

func (Params) GetImages added in v0.9.47

func (p Params) GetImages() map[string]image.Image

func (Params) GetParams added in v0.9.47

func (p Params) GetParams() map[string]string

func (Params) GetRoles added in v0.9.47

func (p Params) GetRoles() map[string]string

type TestCase

type TestCase struct {
	Name         string
	Url          string
	Header       Header
	Model        libQuery.QueryRunnerModel
	Request      any
	Status       int
	CheckBody    []string
	CheckHeader  map[string]string
	DontReadBody bool
	MockError    error
	Desired      any
	DesiredError string
	DesiredResp  string
}

type TestEnv

type TestEnv struct {
	Params    libParams.ParamInterface
	Interface requestCore.RequestCoreInterface
}

func (TestEnv) GetInterface

func (env TestEnv) GetInterface() requestCore.RequestCoreInterface

func (TestEnv) GetParams

func (env TestEnv) GetParams() libParams.ParamInterface

func (*TestEnv) SetInterface

func (env *TestEnv) SetInterface(core requestCore.RequestCoreInterface)

func (*TestEnv) SetParams

func (env *TestEnv) SetParams(params libParams.ParamInterface)

type TestOptions

type TestOptions struct {
	Path            string
	Name            string
	Method          string
	Handler         any
	Middleware      gin.HandlerFunc
	MiddlewareFiber fiber.Handler
	Silent          bool
}

type TestingEnv added in v0.9.47

type TestingEnv interface {
	GetInterface() requestCore.RequestCoreInterface
	GetParams() libParams.ParamInterface
	SetInterface(requestCore.RequestCoreInterface)
	SetParams(libParams.ParamInterface)
}

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"`
}

func (*TestingWsParams) GetFonts

func (p *TestingWsParams) GetFonts() map[string]opentype.Font

func (*TestingWsParams) GetHeaderName

func (p *TestingWsParams) GetHeaderName() string

func (*TestingWsParams) GetImages

func (p *TestingWsParams) GetImages() map[string]image.Image

func (*TestingWsParams) GetLogCompress

func (p *TestingWsParams) GetLogCompress() bool

func (*TestingWsParams) GetLogPath

func (p *TestingWsParams) GetLogPath() string

func (*TestingWsParams) GetLogSize

func (p *TestingWsParams) GetLogSize() int

func (*TestingWsParams) GetParams

func (p *TestingWsParams) GetParams() map[string]string

func (*TestingWsParams) GetRoles

func (p *TestingWsParams) GetRoles() map[string]string

func (*TestingWsParams) GetSkipPaths

func (p *TestingWsParams) GetSkipPaths() []string

Jump to

Keyboard shortcuts

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