testdb

package
v0.0.0-...-6d13c91 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertSQLNullBool

func AssertSQLNullBool(t *testing.T, in sql.NullBool, boolean *bool)

AssertSQLNullBool is a helper to check if the sql.NullBool is equal to the given bool.

func AssertSQLNullStringEqualTo

func AssertSQLNullStringEqualTo(t *testing.T, in sql.NullString, text *string)

AssertSQLNullStringEqualTo is a helper to check if the sql.NullString is equal to the given string.

func RowCount

func RowCount(totalCount int) *sqlmock.Rows

RowCount represents a sql row when count query is executed.

func RowWhenObjectDoesNotExist

func RowWhenObjectDoesNotExist() *sqlmock.Rows

RowWhenObjectDoesNotExist represents a sql row when object does not exist.

func RowWhenObjectExist

func RowWhenObjectExist() *sqlmock.Rows

RowWhenObjectExist represents a sql row when object exist.

Types

type DBMock

type DBMock interface {
	sqlmock.Sqlmock
	AssertExpectations(t *testing.T)
}

DBMock represents a wrapper providing easier interface for asserting expectations.

func MockDatabase

func MockDatabase(t *testing.T) (*sqlx.DB, DBMock)

MockDatabase returns a new *sqlx.DB mock alongside with a wrapper providing easier interface for asserting expectations.

type Mock

type Mock interface {
	AssertExpectations(t mock.TestingT) bool
	On(methodName string, arguments ...interface{}) *mock.Call
}

Mock represents a mockery Mock.

type PageDetails

type PageDetails struct {
	ExpectedModelEntities []interface{}
	ExpectedDBEntities    []interface{}
	ExpectedPage          interface{}
}

PageDetails represents the expected page returned from the List with paging operation. In case of dataloaders a single List operation can return array of pages - a page for each entity that is collected by the dataloader.

type RepoCreateTestSuite

type RepoCreateTestSuite struct {
	Name                      string
	SQLQueryDetails           []SQLQueryDetails
	ConverterMockProvider     func() Mock
	RepoConstructorFunc       interface{}
	ModelEntity               interface{}
	DBEntity                  interface{}
	NilModelEntity            interface{}
	TenantID                  string
	DisableConverterErrorTest bool
	MethodName                string
	IsTopLevelEntity          bool
	IsGlobal                  bool
}

RepoCreateTestSuite represents a generic test suite for repository Create method of any global entity or entity that has externally managed tenants in m2m table/view.

func (*RepoCreateTestSuite) Run

func (suite *RepoCreateTestSuite) Run(t *testing.T) bool

Run runs the generic repo create test suite

type RepoDeleteTestSuite

type RepoDeleteTestSuite struct {
	Name                  string
	SQLQueryDetails       []SQLQueryDetails
	ConverterMockProvider func() Mock
	RepoConstructorFunc   interface{}
	MethodName            string
	MethodArgs            []interface{}
	IsDeleteMany          bool
	IsGlobal              bool
}

RepoDeleteTestSuite represents a generic test suite for repository Delete method of any global entity or entity that has externally managed tenants in m2m table/view.

func (*RepoDeleteTestSuite) Run

func (suite *RepoDeleteTestSuite) Run(t *testing.T) bool

Run runs the generic repo delete test suite

type RepoExistTestSuite

type RepoExistTestSuite struct {
	Name                  string
	SQLQueryDetails       []SQLQueryDetails
	ConverterMockProvider func() Mock
	RepoConstructorFunc   interface{}
	TargetID              string
	TenantID              string
	RefEntity             interface{}
	IsGlobal              bool
	MethodName            string
	MethodArgs            []interface{}
}

RepoExistTestSuite represents a generic test suite for repository Exists method of any entity that has externally managed tenants in m2m table/view. This test suite is not suitable for global entities or entities with embedded tenant in them.

func (*RepoExistTestSuite) Run

func (suite *RepoExistTestSuite) Run(t *testing.T) bool

Run runs the generic repo exists test suite

type RepoGetTestSuite

type RepoGetTestSuite struct {
	Name                                  string
	SQLQueryDetails                       []SQLQueryDetails
	ConverterMockProvider                 func() Mock
	RepoConstructorFunc                   interface{}
	ExpectedModelEntity                   interface{}
	ExpectedDBEntity                      interface{}
	MethodArgs                            []interface{}
	AdditionalConverterArgs               []interface{}
	DisableConverterErrorTest             bool
	MethodName                            string
	ExpectNotFoundError                   bool
	AfterNotFoundErrorSQLQueryDetails     []SQLQueryDetails
	AfterNotFoundErrorExpectedModelEntity interface{}
	AfterNotFoundErrorExpectedDBEntity    interface{}
}

RepoGetTestSuite represents a generic test suite for repository Get method of any global entity or entity that has externally managed tenants in m2m table/view. This test suite is not suitable entities with embedded tenant in them.

func (*RepoGetTestSuite) Run

func (suite *RepoGetTestSuite) Run(t *testing.T) bool

Run runs the generic repo get test suite

type RepoListPageableTestSuite

type RepoListPageableTestSuite struct {
	Name                      string
	SQLQueryDetails           []SQLQueryDetails
	ConverterMockProvider     func() Mock
	RepoConstructorFunc       interface{}
	AdditionalConverterArgs   []interface{}
	Pages                     []PageDetails
	MethodArgs                []interface{}
	DisableConverterErrorTest bool
	MethodName                string
}

RepoListPageableTestSuite represents a generic test suite for repository List with paging methods of any entity that has externally managed tenants in m2m table/view. This test suite is not suitable for global entities or entities with embedded tenant in them.

func (*RepoListPageableTestSuite) Run

func (suite *RepoListPageableTestSuite) Run(t *testing.T) bool

Run runs the generic repo list with paging test suite

type RepoListTestSuite

type RepoListTestSuite struct {
	Name                      string
	SQLQueryDetails           []SQLQueryDetails
	ConverterMockProvider     func() Mock
	ShouldSkipMockFromEntity  bool
	RepoConstructorFunc       interface{}
	ExpectedModelEntities     []interface{}
	ExpectedDBEntities        []interface{}
	MethodArgs                []interface{}
	AdditionalConverterArgs   []interface{}
	DisableConverterErrorTest bool
	MethodName                string
	DisableEmptySliceTest     bool
}

RepoListTestSuite represents a generic test suite for repository List without paging method of any global entity or entity that has externally managed tenants in m2m table/view.

func (*RepoListTestSuite) Run

func (suite *RepoListTestSuite) Run(t *testing.T) bool

Run runs the generic repo list without paging test suite

type RepoUpdateTestSuite

type RepoUpdateTestSuite struct {
	Name                      string
	SQLQueryDetails           []SQLQueryDetails
	ConverterMockProvider     func() Mock
	RepoConstructorFunc       interface{}
	ModelEntity               interface{}
	DBEntity                  interface{}
	NilModelEntity            interface{}
	TenantID                  string
	DisableConverterErrorTest bool
	UpdateMethodName          string
	IsGlobal                  bool
}

RepoUpdateTestSuite represents a generic test suite for repository Update and UpdateWithVersion methods of any global entity or entity that has externally managed tenants in m2m table/view.

func (*RepoUpdateTestSuite) Run

func (suite *RepoUpdateTestSuite) Run(t *testing.T) bool

Run runs the generic repo update test suite

type RepoUpsertTestSuite

type RepoUpsertTestSuite struct {
	Name                      string
	SQLQueryDetails           []SQLQueryDetails
	ConverterMockProvider     func() Mock
	RepoConstructorFunc       interface{}
	ModelEntity               interface{}
	DBEntity                  interface{}
	NilModelEntity            interface{}
	TenantID                  string
	DisableConverterErrorTest bool
	UpsertMethodName          string
}

RepoUpsertTestSuite represents a generic test suite for repository Upsert, TrustedUpsert and UpsertGlobal methods of any entity that has externally managed tenants in m2m table/view. This test suite is not suitable for global entities or entities with embedded tenant in them.

func (*RepoUpsertTestSuite) Run

func (suite *RepoUpsertTestSuite) Run(t *testing.T) bool

Run runs the generic repo upsert test suite

type SQLQueryDetails

type SQLQueryDetails struct {
	Query               string
	IsSelect            bool
	Args                []driver.Value
	ValidResult         driver.Result
	InvalidResult       driver.Result
	ValidRowsProvider   func() []*sqlmock.Rows
	InvalidRowsProvider func() []*sqlmock.Rows
	SkipFailValidation  bool
}

SQLQueryDetails represent an SQL expected query details to provide to the DB mock.

Jump to

Keyboard shortcuts

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