mock

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxWithMock

func CtxWithMock(ctx context.Context, mock ...*Mock) context.Context

func RegisterMockDB

func RegisterMockDB(name string)

RegisterMockDB create an "virtual DB" by using sqllite you should not

Types

type Condition

type Condition interface {
	Match(ctx context.Context, inv *orm.Invocation) bool
}

func NewSimpleCondition

func NewSimpleCondition(tableName string, methodName string) Condition

type DoNothingQueryM2Mer

type DoNothingQueryM2Mer struct{}

DoNothingQueryM2Mer do nothing use it to build mock orm.QueryM2Mer

func (*DoNothingQueryM2Mer) Add

func (d *DoNothingQueryM2Mer) Add(i ...interface{}) (int64, error)

func (*DoNothingQueryM2Mer) AddWithCtx

func (d *DoNothingQueryM2Mer) AddWithCtx(ctx context.Context, i ...interface{}) (int64, error)

func (*DoNothingQueryM2Mer) Clear

func (d *DoNothingQueryM2Mer) Clear() (int64, error)

func (*DoNothingQueryM2Mer) ClearWithCtx

func (d *DoNothingQueryM2Mer) ClearWithCtx(ctx context.Context) (int64, error)

func (*DoNothingQueryM2Mer) Count

func (d *DoNothingQueryM2Mer) Count() (int64, error)

func (*DoNothingQueryM2Mer) CountWithCtx

func (d *DoNothingQueryM2Mer) CountWithCtx(ctx context.Context) (int64, error)

func (*DoNothingQueryM2Mer) Exist

func (d *DoNothingQueryM2Mer) Exist(i interface{}) bool

func (*DoNothingQueryM2Mer) ExistWithCtx

func (d *DoNothingQueryM2Mer) ExistWithCtx(ctx context.Context, i interface{}) bool

func (*DoNothingQueryM2Mer) Remove

func (d *DoNothingQueryM2Mer) Remove(i ...interface{}) (int64, error)

func (*DoNothingQueryM2Mer) RemoveWithCtx

func (d *DoNothingQueryM2Mer) RemoveWithCtx(ctx context.Context, i ...interface{}) (int64, error)

type DoNothingQuerySetter

type DoNothingQuerySetter struct{}

DoNothingQuerySetter do nothing usually you use this to build your mock QuerySetter

func (*DoNothingQuerySetter) Aggregate

func (d *DoNothingQuerySetter) Aggregate(s string) orm.QuerySeter

func (*DoNothingQuerySetter) All

func (d *DoNothingQuerySetter) All(container interface{}, cols ...string) (int64, error)

func (*DoNothingQuerySetter) AllWithCtx

func (d *DoNothingQuerySetter) AllWithCtx(ctx context.Context, container interface{}, cols ...string) (int64, error)

func (*DoNothingQuerySetter) Count

func (d *DoNothingQuerySetter) Count() (int64, error)

func (*DoNothingQuerySetter) CountWithCtx

func (d *DoNothingQuerySetter) CountWithCtx(ctx context.Context) (int64, error)

func (*DoNothingQuerySetter) Delete

func (d *DoNothingQuerySetter) Delete() (int64, error)

func (*DoNothingQuerySetter) DeleteWithCtx

func (d *DoNothingQuerySetter) DeleteWithCtx(ctx context.Context) (int64, error)

func (*DoNothingQuerySetter) Distinct

func (d *DoNothingQuerySetter) Distinct() orm.QuerySeter

func (*DoNothingQuerySetter) Exclude

func (d *DoNothingQuerySetter) Exclude(s string, i ...interface{}) orm.QuerySeter

func (*DoNothingQuerySetter) Exist

func (d *DoNothingQuerySetter) Exist() bool

func (*DoNothingQuerySetter) ExistWithCtx

func (d *DoNothingQuerySetter) ExistWithCtx(ctx context.Context) bool

func (*DoNothingQuerySetter) Filter

func (d *DoNothingQuerySetter) Filter(s string, i ...interface{}) orm.QuerySeter

func (*DoNothingQuerySetter) FilterRaw

func (d *DoNothingQuerySetter) FilterRaw(s string, s2 string) orm.QuerySeter

func (*DoNothingQuerySetter) ForUpdate

func (d *DoNothingQuerySetter) ForUpdate() orm.QuerySeter

func (*DoNothingQuerySetter) ForceIndex

func (d *DoNothingQuerySetter) ForceIndex(indexes ...string) orm.QuerySeter

func (*DoNothingQuerySetter) GetCond

func (d *DoNothingQuerySetter) GetCond() *orm.Condition

func (*DoNothingQuerySetter) GroupBy

func (d *DoNothingQuerySetter) GroupBy(exprs ...string) orm.QuerySeter

func (*DoNothingQuerySetter) IgnoreIndex

func (d *DoNothingQuerySetter) IgnoreIndex(indexes ...string) orm.QuerySeter

func (*DoNothingQuerySetter) Limit

func (d *DoNothingQuerySetter) Limit(limit interface{}, args ...interface{}) orm.QuerySeter

func (*DoNothingQuerySetter) Offset

func (d *DoNothingQuerySetter) Offset(offset interface{}) orm.QuerySeter

func (*DoNothingQuerySetter) One

func (d *DoNothingQuerySetter) One(container interface{}, cols ...string) error

func (*DoNothingQuerySetter) OneWithCtx

func (d *DoNothingQuerySetter) OneWithCtx(ctx context.Context, container interface{}, cols ...string) error

func (*DoNothingQuerySetter) OrderBy

func (d *DoNothingQuerySetter) OrderBy(exprs ...string) orm.QuerySeter

func (*DoNothingQuerySetter) OrderClauses

func (d *DoNothingQuerySetter) OrderClauses(orders ...*order_clause.Order) orm.QuerySeter

func (*DoNothingQuerySetter) PrepareInsert

func (d *DoNothingQuerySetter) PrepareInsert() (orm.Inserter, error)

func (*DoNothingQuerySetter) PrepareInsertWithCtx

func (d *DoNothingQuerySetter) PrepareInsertWithCtx(ctx context.Context) (orm.Inserter, error)

func (*DoNothingQuerySetter) RelatedSel

func (d *DoNothingQuerySetter) RelatedSel(params ...interface{}) orm.QuerySeter

func (*DoNothingQuerySetter) RowsToMap

func (d *DoNothingQuerySetter) RowsToMap(result *orm.Params, keyCol, valueCol string) (int64, error)

func (*DoNothingQuerySetter) RowsToStruct

func (d *DoNothingQuerySetter) RowsToStruct(ptrStruct interface{}, keyCol, valueCol string) (int64, error)

func (*DoNothingQuerySetter) SetCond

func (d *DoNothingQuerySetter) SetCond(condition *orm.Condition) orm.QuerySeter

func (*DoNothingQuerySetter) Update

func (d *DoNothingQuerySetter) Update(values orm.Params) (int64, error)

func (*DoNothingQuerySetter) UpdateWithCtx

func (d *DoNothingQuerySetter) UpdateWithCtx(ctx context.Context, values orm.Params) (int64, error)

func (*DoNothingQuerySetter) UseIndex

func (d *DoNothingQuerySetter) UseIndex(indexes ...string) orm.QuerySeter

func (*DoNothingQuerySetter) Values

func (d *DoNothingQuerySetter) Values(results *[]orm.Params, exprs ...string) (int64, error)

func (*DoNothingQuerySetter) ValuesFlat

func (d *DoNothingQuerySetter) ValuesFlat(result *orm.ParamsList, expr string) (int64, error)

func (*DoNothingQuerySetter) ValuesFlatWithCtx

func (d *DoNothingQuerySetter) ValuesFlatWithCtx(ctx context.Context, result *orm.ParamsList, expr string) (int64, error)

func (*DoNothingQuerySetter) ValuesList

func (d *DoNothingQuerySetter) ValuesList(results *[]orm.ParamsList, exprs ...string) (int64, error)

func (*DoNothingQuerySetter) ValuesListWithCtx

func (d *DoNothingQuerySetter) ValuesListWithCtx(ctx context.Context, results *[]orm.ParamsList, exprs ...string) (int64, error)

func (*DoNothingQuerySetter) ValuesWithCtx

func (d *DoNothingQuerySetter) ValuesWithCtx(ctx context.Context, results *[]orm.Params, exprs ...string) (int64, error)

type DoNothingRawSetter

type DoNothingRawSetter struct{}

func (*DoNothingRawSetter) Exec

func (d *DoNothingRawSetter) Exec() (sql.Result, error)

func (*DoNothingRawSetter) Prepare

func (d *DoNothingRawSetter) Prepare() (orm.RawPreparer, error)

func (*DoNothingRawSetter) QueryRow

func (d *DoNothingRawSetter) QueryRow(containers ...interface{}) error

func (*DoNothingRawSetter) QueryRows

func (d *DoNothingRawSetter) QueryRows(containers ...interface{}) (int64, error)

func (*DoNothingRawSetter) RowsToMap

func (d *DoNothingRawSetter) RowsToMap(result *orm.Params, keyCol, valueCol string) (int64, error)

func (*DoNothingRawSetter) RowsToStruct

func (d *DoNothingRawSetter) RowsToStruct(ptrStruct interface{}, keyCol, valueCol string) (int64, error)

func (*DoNothingRawSetter) SetArgs

func (d *DoNothingRawSetter) SetArgs(i ...interface{}) orm.RawSeter

func (*DoNothingRawSetter) Values

func (d *DoNothingRawSetter) Values(container *[]orm.Params, cols ...string) (int64, error)

func (*DoNothingRawSetter) ValuesFlat

func (d *DoNothingRawSetter) ValuesFlat(container *orm.ParamsList, cols ...string) (int64, error)

func (*DoNothingRawSetter) ValuesList

func (d *DoNothingRawSetter) ValuesList(container *[]orm.ParamsList, cols ...string) (int64, error)

type Mock

type Mock struct {
	// contains filtered or unexported fields
}

func MockCommit

func MockCommit(err error) *Mock

MockCommit support Commit

func MockDBStats

func MockDBStats(stats *sql.DBStats) *Mock

MockDBStats support DBStats

func MockDeleteWithCtx

func MockDeleteWithCtx(tableName string, affectedRow int64, err error) *Mock

MockDeleteWithCtx support Delete and DeleteWithCtx

func MockInsertMultiWithCtx

func MockInsertMultiWithCtx(tableName string, cnt int64, err error) *Mock

MockInsertMultiWithCtx support InsertMulti and InsertMultiWithCtx

func MockInsertOrUpdateWithCtx

func MockInsertOrUpdateWithCtx(tableName string, id int64, err error) *Mock

MockInsertOrUpdateWithCtx support InsertOrUpdate and InsertOrUpdateWithCtx

func MockInsertWithCtx

func MockInsertWithCtx(tableName string, id int64, err error) *Mock

MockInsertWithCtx support Insert and InsertWithCtx

func MockLoadRelatedWithCtx

func MockLoadRelatedWithCtx(tableName string, name string, rows int64, err error) *Mock

MockLoadRelatedWithCtx support LoadRelatedWithCtx and LoadRelated

func MockMethod

func MockMethod(method string, resp ...interface{}) *Mock

MockMethod only check method name

func MockQueryM2MWithCtx

func MockQueryM2MWithCtx(tableName string, name string, res orm.QueryM2Mer) *Mock

MockQueryM2MWithCtx support QueryM2MWithCtx and QueryM2M Now you may be need to use golang/mock to generate QueryM2M mock instance Or use DoNothingQueryM2Mer for example:

post := Post{Id: 4}
m2m := Ormer.QueryM2M(&post, "Tags")

when you write test code: MockQueryM2MWithCtx("post", "Tags", mockM2Mer) "post" is the table name of model Post structure TODO provide orm.QueryM2Mer

func MockQueryTableWithCtx

func MockQueryTableWithCtx(tableName string, qs orm.QuerySeter) *Mock

MockQueryTableWithCtx support QueryTableWithCtx and QueryTable

func MockRawWithCtx

func MockRawWithCtx(rs orm.RawSeter) *Mock

MockRawWithCtx support RawWithCtx and Raw

func MockRead

func MockRead(tableName string, cb func(data interface{}), err error) *Mock

MockRead support orm.Read and orm.ReadWithCtx cb is used to mock read data from DB

func MockReadForUpdateWithCtx

func MockReadForUpdateWithCtx(tableName string, cb func(data interface{}), err error) *Mock

MockReadForUpdateWithCtx support ReadForUpdate and ReadForUpdateWithCtx cb is used to mock read data from DB

func MockReadOrCreateWithCtx

func MockReadOrCreateWithCtx(tableName string,
	cb func(data interface{}),
	insert bool, id int64, err error) *Mock

MockReadOrCreateWithCtx support ReadOrCreate and ReadOrCreateWithCtx cb is used to mock read data from DB

func MockRollback

func MockRollback(err error) *Mock

MockRollback support Rollback

func MockRollbackUnlessCommit

func MockRollbackUnlessCommit(err error) *Mock

MockRollbackUnlessCommit support RollbackUnlessCommit

func MockTable

func MockTable(tableName string, resp ...interface{}) *Mock

MockTable only check table name

func MockUpdateWithCtx

func MockUpdateWithCtx(tableName string, affectedRow int64, err error) *Mock

MockUpdateWithCtx support UpdateWithCtx and Update

func NewMock

func NewMock(cond Condition, resp []interface{}, cb func(inv *orm.Invocation)) *Mock

type OrmStub

type OrmStub struct {
	// contains filtered or unexported fields
}

func (*OrmStub) Clear

func (o *OrmStub) Clear()

func (*OrmStub) FilterChain

func (o *OrmStub) FilterChain(next orm.Filter) orm.Filter

func (*OrmStub) Mock

func (o *OrmStub) Mock(m *Mock)

type QueryM2MerCondition

type QueryM2MerCondition struct {
	// contains filtered or unexported fields
}

func NewQueryM2MerCondition

func NewQueryM2MerCondition(tableName string, name string) *QueryM2MerCondition

func (*QueryM2MerCondition) Match

func (q *QueryM2MerCondition) Match(ctx context.Context, inv *orm.Invocation) bool

type SimpleCondition

type SimpleCondition struct {
	// contains filtered or unexported fields
}

func (*SimpleCondition) Match

func (s *SimpleCondition) Match(ctx context.Context, inv *orm.Invocation) bool

type Stub

type Stub interface {
	Mock(m *Mock)
	Clear()
}

func StartMock

func StartMock() Stub

Jump to

Keyboard shortcuts

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