Documentation ¶
Overview ¶
Package reltest for unit testing database interaction.
Example ¶
package main import ( "context" "fmt" "github.com/go-rel/rel/where" "github.com/go-rel/reltest" ) type Movie struct { ID int Title string } func main() { var ( repo = reltest.New() ) // Mock query repo.ExpectFind(where.Eq("id", 1)).Result(Movie{ID: 1, Title: "Golang"}) var movie Movie repo.MustFind(context.Background(), &movie, where.Eq("id", 1)) fmt.Println(movie.Title) }
Output: Golang
Index ¶
- Variables
- type Assert
- type EntityMockDelete
- type EntityMockDeleteAll
- type EntityMockFind
- type EntityMockFindAll
- type EntityMockFindAndCountAll
- type EntityMockInsertAll
- type EntityMockIterate
- type EntityMockMutate
- type EntityMockPreload
- type EntityMockPreloadAll
- type EntityRepository
- func (er *EntityRepository[T]) AssertExpectations(t TestingT) bool
- func (er *EntityRepository[T]) ExpectAggregate(query rel.Query, aggregate string, field string) *MockAggregate
- func (er *EntityRepository[T]) ExpectCount(collection string, queriers ...rel.Querier) *MockCount
- func (er *EntityRepository[T]) ExpectDelete(options ...rel.Mutator) *EntityMockDelete[T]
- func (er *EntityRepository[T]) ExpectDeleteAll() *EntityMockDeleteAll[T]
- func (er *EntityRepository[T]) ExpectFind(queriers ...rel.Querier) *EntityMockFind[T]
- func (er *EntityRepository[T]) ExpectFindAll(queriers ...rel.Querier) *EntityMockFindAll[T]
- func (er *EntityRepository[T]) ExpectFindAndCountAll(queriers ...rel.Querier) *EntityMockFindAndCountAll[T]
- func (er *EntityRepository[T]) ExpectInsert(mutators ...rel.Mutator) *EntityMockMutate[T]
- func (er *EntityRepository[T]) ExpectInsertAll() *EntityMockInsertAll[T]
- func (er *EntityRepository[T]) ExpectIterate(query rel.Query, options ...rel.IteratorOption) *EntityMockIterate[T]
- func (er *EntityRepository[T]) ExpectPreload(field string, queriers ...rel.Querier) *EntityMockPreload[T]
- func (er *EntityRepository[T]) ExpectPreloadAll(field string, queriers ...rel.Querier) *EntityMockPreloadAll[T]
- func (er *EntityRepository[T]) ExpectTransaction(fn func(*Repository))
- func (er *EntityRepository[T]) ExpectUpdate(mutators ...rel.Mutator) *EntityMockMutate[T]
- func (er *EntityRepository[T]) WrapTransaction(repository *Repository) *EntityRepository[T]
- type MockAggregate
- type MockCount
- type MockDelete
- func (md *MockDelete) ConnectionClosed() *Assert
- func (md *MockDelete) Error(err error) *Assert
- func (md MockDelete) ExpectString() string
- func (md *MockDelete) For(entity any) *MockDelete
- func (md *MockDelete) ForContains(contains any) *MockDelete
- func (md *MockDelete) ForTable(typ string) *MockDelete
- func (md *MockDelete) ForType(typ string) *MockDelete
- func (md MockDelete) String() string
- func (md *MockDelete) Success() *Assert
- type MockDeleteAll
- func (mda *MockDeleteAll) ConnectionClosed() *Assert
- func (mda *MockDeleteAll) Error(err error) *Assert
- func (mda MockDeleteAll) ExpectString() string
- func (mda *MockDeleteAll) For(entity any) *MockDeleteAll
- func (mda *MockDeleteAll) ForTable(typ string) *MockDeleteAll
- func (mda *MockDeleteAll) ForType(typ string) *MockDeleteAll
- func (mda MockDeleteAll) String() string
- func (mda *MockDeleteAll) Success() *Assert
- type MockDeleteAny
- func (mda *MockDeleteAny) ConnectionClosed() *Assert
- func (mda *MockDeleteAny) DeletedCount(deletedCount int) *Assert
- func (mda *MockDeleteAny) Error(err error) *Assert
- func (mda MockDeleteAny) ExpectString() string
- func (mda MockDeleteAny) String() string
- func (mda *MockDeleteAny) Success() *Assert
- func (mda *MockDeleteAny) Unsafe() *MockDeleteAny
- type MockExec
- type MockFind
- type MockFindAll
- type MockFindAndCountAll
- type MockInsertAll
- func (mia *MockInsertAll) ConnectionClosed() *Assert
- func (mia *MockInsertAll) Error(err error) *Assert
- func (mia MockInsertAll) ExpectString() string
- func (mia *MockInsertAll) For(entity any) *MockInsertAll
- func (mia *MockInsertAll) ForTable(typ string) *MockInsertAll
- func (mia *MockInsertAll) ForType(typ string) *MockInsertAll
- func (mia *MockInsertAll) NotUnique(key string) *Assert
- func (mia MockInsertAll) String() string
- func (mia *MockInsertAll) Success() *Assert
- type MockIterate
- func (mi MockIterate) Close() error
- func (mi *MockIterate) ConnectionClosed() *Assert
- func (mi *MockIterate) Error(err error) *Assert
- func (mi MockIterate) ExpectString() string
- func (mi *MockIterate) Next(entity any) error
- func (mi *MockIterate) Result(result any) *Assert
- func (mi MockIterate) String() string
- type MockMutate
- func (mm *MockMutate) ConnectionClosed() *Assert
- func (mm *MockMutate) Error(err error) *Assert
- func (mm MockMutate) ExpectString() string
- func (mm *MockMutate) For(entity any) *MockMutate
- func (mm *MockMutate) ForContains(contains any) *MockMutate
- func (mm *MockMutate) ForTable(typ string) *MockMutate
- func (mm *MockMutate) ForType(typ string) *MockMutate
- func (mm *MockMutate) NotUnique(key string) *Assert
- func (mm MockMutate) String() string
- func (mm *MockMutate) Success() *Assert
- type MockPreload
- func (mp *MockPreload) ConnectionClosed() *Assert
- func (mp *MockPreload) Error(err error) *Assert
- func (mp MockPreload) ExpectString() string
- func (md *MockPreload) For(entities any) *MockPreload
- func (md *MockPreload) ForType(typ string) *MockPreload
- func (mp *MockPreload) Result(result any) *Assert
- func (mp MockPreload) String() string
- type MockUpdateAny
- func (mua *MockUpdateAny) ConnectionClosed() *Assert
- func (mua *MockUpdateAny) Error(err error) *Assert
- func (mua MockUpdateAny) ExpectString() string
- func (mua MockUpdateAny) String() string
- func (mua *MockUpdateAny) Unsafe() *MockUpdateAny
- func (mua *MockUpdateAny) UpdatedCount(updatedCount int) *Assert
- type Repository
- func (r *Repository) Adapter(ctx context.Context) rel.Adapter
- func (r *Repository) Aggregate(ctx context.Context, query rel.Query, aggregate string, field string) (int, error)
- func (r *Repository) AssertExpectations(t TestingT) bool
- func (r *Repository) Count(ctx context.Context, collection string, queriers ...rel.Querier) (int, error)
- func (r *Repository) Delete(ctx context.Context, entity any, options ...rel.Mutator) error
- func (r *Repository) DeleteAll(ctx context.Context, entities any) error
- func (r *Repository) DeleteAny(ctx context.Context, query rel.Query) (int, error)
- func (r *Repository) Exec(ctx context.Context, statement string, args ...any) (int, int, error)
- func (r *Repository) ExpectAggregate(query rel.Query, aggregate string, field string) *MockAggregate
- func (r *Repository) ExpectCount(collection string, queriers ...rel.Querier) *MockCount
- func (r *Repository) ExpectDelete(options ...rel.Mutator) *MockDelete
- func (r *Repository) ExpectDeleteAll() *MockDeleteAll
- func (r *Repository) ExpectDeleteAny(query rel.Query) *MockDeleteAny
- func (r *Repository) ExpectExec(statement string, args ...any) *MockExec
- func (r *Repository) ExpectFind(queriers ...rel.Querier) *MockFind
- func (r *Repository) ExpectFindAll(queriers ...rel.Querier) *MockFindAll
- func (r *Repository) ExpectFindAndCountAll(queriers ...rel.Querier) *MockFindAndCountAll
- func (r *Repository) ExpectInsert(mutators ...rel.Mutator) *MockMutate
- func (r *Repository) ExpectInsertAll() *MockInsertAll
- func (r *Repository) ExpectIterate(query rel.Query, options ...rel.IteratorOption) *MockIterate
- func (r *Repository) ExpectPreload(field string, queriers ...rel.Querier) *MockPreload
- func (r *Repository) ExpectTransaction(fn func(*Repository))
- func (r *Repository) ExpectUpdate(mutators ...rel.Mutator) *MockMutate
- func (r *Repository) ExpectUpdateAny(query rel.Query, mutates ...rel.Mutate) *MockUpdateAny
- func (r *Repository) Find(ctx context.Context, entity any, queriers ...rel.Querier) error
- func (r *Repository) FindAll(ctx context.Context, entities any, queriers ...rel.Querier) error
- func (r *Repository) FindAndCountAll(ctx context.Context, entities any, queriers ...rel.Querier) (int, error)
- func (r *Repository) Insert(ctx context.Context, entity any, mutators ...rel.Mutator) error
- func (r *Repository) InsertAll(ctx context.Context, entities any, mutators ...rel.Mutator) error
- func (r *Repository) Instrumentation(instrumenter rel.Instrumenter)
- func (r *Repository) Iterate(ctx context.Context, query rel.Query, options ...rel.IteratorOption) rel.Iterator
- func (r *Repository) MustAggregate(ctx context.Context, query rel.Query, aggregate string, field string) int
- func (r *Repository) MustCount(ctx context.Context, collection string, queriers ...rel.Querier) int
- func (r *Repository) MustDelete(ctx context.Context, entity any, options ...rel.Mutator)
- func (r *Repository) MustDeleteAll(ctx context.Context, entity any)
- func (r *Repository) MustDeleteAny(ctx context.Context, query rel.Query) int
- func (r *Repository) MustExec(ctx context.Context, statement string, args ...any) (int, int)
- func (r *Repository) MustFind(ctx context.Context, entity any, queriers ...rel.Querier)
- func (r *Repository) MustFindAll(ctx context.Context, entities any, queriers ...rel.Querier)
- func (r *Repository) MustFindAndCountAll(ctx context.Context, entities any, queriers ...rel.Querier) int
- func (r *Repository) MustInsert(ctx context.Context, entity any, mutators ...rel.Mutator)
- func (r *Repository) MustInsertAll(ctx context.Context, entities any, mutators ...rel.Mutator)
- func (r *Repository) MustPreload(ctx context.Context, entities any, field string, queriers ...rel.Querier)
- func (r *Repository) MustUpdate(ctx context.Context, entity any, mutators ...rel.Mutator)
- func (r *Repository) MustUpdateAny(ctx context.Context, query rel.Query, mutates ...rel.Mutate) int
- func (r *Repository) Ping(ctx context.Context) error
- func (r *Repository) Preload(ctx context.Context, entities any, field string, queriers ...rel.Querier) error
- func (r *Repository) Transaction(ctx context.Context, fn func(ctx context.Context) error) error
- func (r *Repository) Update(ctx context.Context, entity any, mutators ...rel.Mutator) error
- func (r *Repository) UpdateAny(ctx context.Context, query rel.Query, mutates ...rel.Mutate) (int, error)
- type TestingT
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Any any = anyValue{}
var ( // ErrConnectionClosed is alias for sql.ErrConnDone. ErrConnectionClosed = sql.ErrConnDone )
Functions ¶
This section is empty.
Types ¶
type Assert ¶
type Assert struct {
// contains filtered or unexported fields
}
type EntityMockDelete ¶ added in v0.11.0
type EntityMockDelete[T any] struct {
*MockDelete
}
EntityMockDelete mock wrapper
func (*EntityMockDelete[T]) For ¶ added in v0.11.0
func (emd *EntityMockDelete[T]) For(result *T) *EntityMockDelete[T]
For assert calls for given entity.
type EntityMockDeleteAll ¶ added in v0.11.0
type EntityMockDeleteAll[T any] struct {
*MockDeleteAll
}
EntityMockDeleteAll mock wrapper
func (*EntityMockDeleteAll[T]) For ¶ added in v0.11.0
func (emda *EntityMockDeleteAll[T]) For(result *[]T) *EntityMockDeleteAll[T]
For assert calls for given entity.
type EntityMockFind ¶ added in v0.11.0
type EntityMockFind[T any] struct {
*MockFind
}
EntityMockFind mock wrapper
func (*EntityMockFind[T]) Result ¶ added in v0.11.0
func (emf *EntityMockFind[T]) Result(result T) *Assert
Result sets the result of this query.
type EntityMockFindAll ¶ added in v0.11.0
type EntityMockFindAll[T any] struct {
*MockFindAll
}
EntityMockFindAll mock wrapper
func (*EntityMockFindAll[T]) Result ¶ added in v0.11.0
func (emfa *EntityMockFindAll[T]) Result(result []T) *Assert
Result sets the result of this query.
type EntityMockFindAndCountAll ¶ added in v0.11.0
type EntityMockFindAndCountAll[T any] struct {
*MockFindAndCountAll
}
EntityMockFindAndCountAll mock wrapper
func (*EntityMockFindAndCountAll[T]) Result ¶ added in v0.11.0
func (emfaca *EntityMockFindAndCountAll[T]) Result(result []T, count int) *Assert
Result sets the result of this query.
type EntityMockInsertAll ¶ added in v0.11.0
type EntityMockInsertAll[T any] struct {
*MockInsertAll
}
EntityMockInsertAll mock wrapper
func (*EntityMockInsertAll[T]) For ¶ added in v0.11.0
func (emia *EntityMockInsertAll[T]) For(result *[]T) *EntityMockInsertAll[T]
For assert calls for given entity.
type EntityMockIterate ¶ added in v0.11.0
type EntityMockIterate[T any] struct {
*MockIterate
}
EntityMockIterate mock wrapper
func (*EntityMockIterate[T]) Result ¶ added in v0.11.0
func (emi *EntityMockIterate[T]) Result(result []T) *Assert
Result sets the result of preload.
type EntityMockMutate ¶ added in v0.11.0
type EntityMockMutate[T any] struct {
*MockMutate
}
EntityMockMutate mock wrapper
func (*EntityMockMutate[T]) For ¶ added in v0.11.0
func (emm *EntityMockMutate[T]) For(result *T) *EntityMockMutate[T]
Result sets the result of this query.
type EntityMockPreload ¶ added in v0.11.0
type EntityMockPreload[T any] struct {
*MockPreload
}
EntityMockPreload mock wrapper
func (*EntityMockPreload[T]) For ¶ added in v0.11.0
func (emp *EntityMockPreload[T]) For(result *T) *EntityMockPreload[T]
For assert calls for given entity.
type EntityMockPreloadAll ¶ added in v0.11.0
type EntityMockPreloadAll[T any] struct {
*MockPreload
}
EntityMockPreloadAll mock wrapper
func (*EntityMockPreloadAll[T]) For ¶ added in v0.11.0
func (empa *EntityMockPreloadAll[T]) For(result *[]T) *EntityMockPreloadAll[T]
For assert calls for given entity.
type EntityRepository ¶ added in v0.11.0
type EntityRepository[T any] struct { rel.EntityRepository[T] // contains filtered or unexported fields }
EntityRepository mock
func NewEntityRepository ¶ added in v0.11.0
func NewEntityRepository[T any]() *EntityRepository[T]
func (*EntityRepository[T]) AssertExpectations ¶ added in v0.11.0
func (er *EntityRepository[T]) AssertExpectations(t TestingT) bool
AssertExpectations asserts that everything was in fact called as expected. Calls may have occurred in any order.
func (*EntityRepository[T]) ExpectAggregate ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectAggregate(query rel.Query, aggregate string, field string) *MockAggregate
ExpectAggregate apply mocks and expectations for Aggregate
func (*EntityRepository[T]) ExpectCount ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectCount(collection string, queriers ...rel.Querier) *MockCount
ExpectCount apply mocks and expectations for Count
func (*EntityRepository[T]) ExpectDelete ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectDelete(options ...rel.Mutator) *EntityMockDelete[T]
ExpectDelete apply mocks and expectations for Delete
func (*EntityRepository[T]) ExpectDeleteAll ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectDeleteAll() *EntityMockDeleteAll[T]
ExpectDeleteAll apply mocks and expectations for DeleteAll
func (*EntityRepository[T]) ExpectFind ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectFind(queriers ...rel.Querier) *EntityMockFind[T]
ExpectFind apply mocks and expectations for Find
func (*EntityRepository[T]) ExpectFindAll ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectFindAll(queriers ...rel.Querier) *EntityMockFindAll[T]
ExpectFindAll apply mocks and expectations for FindAll
func (*EntityRepository[T]) ExpectFindAndCountAll ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectFindAndCountAll(queriers ...rel.Querier) *EntityMockFindAndCountAll[T]
ExpectFindAndCountAll apply mocks and expectations for FindAndCountAll
func (*EntityRepository[T]) ExpectInsert ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectInsert(mutators ...rel.Mutator) *EntityMockMutate[T]
ExpectInsert apply mocks and expectations for Insert
func (*EntityRepository[T]) ExpectInsertAll ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectInsertAll() *EntityMockInsertAll[T]
ExpectInsertAll entities.
func (*EntityRepository[T]) ExpectIterate ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectIterate(query rel.Query, options ...rel.IteratorOption) *EntityMockIterate[T]
ExpectIterate apply mocks and expectations for Iterate
func (*EntityRepository[T]) ExpectPreload ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectPreload(field string, queriers ...rel.Querier) *EntityMockPreload[T]
ExpectPreload apply mocks and expectations for Preload
func (*EntityRepository[T]) ExpectPreloadAll ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectPreloadAll(field string, queriers ...rel.Querier) *EntityMockPreloadAll[T]
ExpectPreload apply mocks and expectations for Preload
func (*EntityRepository[T]) ExpectTransaction ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectTransaction(fn func(*Repository))
ExpectTransaction declare expectation inside transaction.
func (*EntityRepository[T]) ExpectUpdate ¶ added in v0.11.0
func (er *EntityRepository[T]) ExpectUpdate(mutators ...rel.Mutator) *EntityMockMutate[T]
ExpectUpdate apply mocks and expectations for Update
func (*EntityRepository[T]) WrapTransaction ¶ added in v0.11.0
func (er *EntityRepository[T]) WrapTransaction(repository *Repository) *EntityRepository[T]
WrapTransaction repository
type MockAggregate ¶
type MockAggregate struct {
// contains filtered or unexported fields
}
MockAggregate asserts and simulate UpdateAny function for test.
func (*MockAggregate) ConnectionClosed ¶
func (ma *MockAggregate) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.
func (*MockAggregate) Error ¶
func (ma *MockAggregate) Error(err error) *Assert
Error sets error to be returned.
func (MockAggregate) ExpectString ¶
func (ma MockAggregate) ExpectString() string
ExpectString representation of mocked call.
func (*MockAggregate) Result ¶
func (ma *MockAggregate) Result(count int) *Assert
Result sets the result of this query.
func (MockAggregate) String ¶
func (ma MockAggregate) String() string
String representation of mocked call.
type MockCount ¶
type MockCount struct {
// contains filtered or unexported fields
}
MockCount asserts and simulate UpdateAny function for test.
func (*MockCount) ConnectionClosed ¶
ConnectionClosed sets this error to be returned.
func (MockCount) ExpectString ¶
ExpectString representation of mocked call.
type MockDelete ¶
type MockDelete struct {
// contains filtered or unexported fields
}
MockDelete asserts and simulate Delete function for test.
func (*MockDelete) ConnectionClosed ¶
func (md *MockDelete) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.
func (*MockDelete) Error ¶
func (md *MockDelete) Error(err error) *Assert
Error sets error to be returned.
func (MockDelete) ExpectString ¶
func (md MockDelete) ExpectString() string
ExpectString representation of mocked call.
func (*MockDelete) For ¶
func (md *MockDelete) For(entity any) *MockDelete
For assert calls for given entity.
func (*MockDelete) ForContains ¶
func (md *MockDelete) ForContains(contains any) *MockDelete
ForContains assert calls to contains some value of given struct.
func (*MockDelete) ForTable ¶
func (md *MockDelete) ForTable(typ string) *MockDelete
ForTable assert calls for given table.
func (*MockDelete) ForType ¶
func (md *MockDelete) ForType(typ string) *MockDelete
ForType assert calls for given type. Type must include package name, example: `model.User`.
func (MockDelete) String ¶
func (md MockDelete) String() string
String representation of mocked call.
func (*MockDelete) Success ¶
func (md *MockDelete) Success() *Assert
Success sets no error to be returned.
type MockDeleteAll ¶
type MockDeleteAll struct {
// contains filtered or unexported fields
}
MockDeleteAll asserts and simulate Delete function for test.
func (*MockDeleteAll) ConnectionClosed ¶
func (mda *MockDeleteAll) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.
func (*MockDeleteAll) Error ¶
func (mda *MockDeleteAll) Error(err error) *Assert
Error sets error to be returned.
func (MockDeleteAll) ExpectString ¶
func (mda MockDeleteAll) ExpectString() string
ExpectString representation of mocked call.
func (*MockDeleteAll) For ¶
func (mda *MockDeleteAll) For(entity any) *MockDeleteAll
For assert calls for given entity.
func (*MockDeleteAll) ForTable ¶
func (mda *MockDeleteAll) ForTable(typ string) *MockDeleteAll
ForTable assert calls for given table.
func (*MockDeleteAll) ForType ¶
func (mda *MockDeleteAll) ForType(typ string) *MockDeleteAll
ForType assert calls for given type. Type must include package name, example: `model.User`.
func (MockDeleteAll) String ¶
func (mda MockDeleteAll) String() string
String representation of mocked call.
func (*MockDeleteAll) Success ¶
func (mda *MockDeleteAll) Success() *Assert
Success sets no error to be returned.
type MockDeleteAny ¶
type MockDeleteAny struct {
// contains filtered or unexported fields
}
MockDeleteAny asserts and simulate DeleteAny function for test.
func (*MockDeleteAny) ConnectionClosed ¶
func (mda *MockDeleteAny) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.
func (*MockDeleteAny) DeletedCount ¶
func (mda *MockDeleteAny) DeletedCount(deletedCount int) *Assert
DeletedCount set the returned deleted count of this function.
func (*MockDeleteAny) Error ¶
func (mda *MockDeleteAny) Error(err error) *Assert
Error sets error to be returned.
func (MockDeleteAny) ExpectString ¶
func (mda MockDeleteAny) ExpectString() string
ExpectString representation of mocked call.
func (MockDeleteAny) String ¶
func (mda MockDeleteAny) String() string
String representation of mocked call.
func (*MockDeleteAny) Success ¶
func (mda *MockDeleteAny) Success() *Assert
Success sets no error to be returned.
func (*MockDeleteAny) Unsafe ¶
func (mda *MockDeleteAny) Unsafe() *MockDeleteAny
Unsafe allows for unsafe operation to delete entities without where condition.
type MockExec ¶
type MockExec struct {
// contains filtered or unexported fields
}
MockExec asserts and simulate UpdateAny function for test.
func (*MockExec) ConnectionClosed ¶
ConnectionClosed sets this error to be returned.
func (MockExec) ExpectString ¶
ExpectString representation of mocked call.
type MockFind ¶
type MockFind struct {
// contains filtered or unexported fields
}
MockFind asserts and simulate find function for test.
func (*MockFind) ConnectionClosed ¶
ConnectionClosed sets this error to be returned.
func (MockFind) ExpectString ¶
ExpectString representation of mocked call.
type MockFindAll ¶
type MockFindAll struct {
// contains filtered or unexported fields
}
MockFindAll asserts and simulate find all function for test.
func (*MockFindAll) ConnectionClosed ¶
func (mfa *MockFindAll) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.
func (*MockFindAll) Error ¶
func (mfa *MockFindAll) Error(err error) *Assert
Error sets error to be returned.
func (MockFindAll) ExpectString ¶
func (mfa MockFindAll) ExpectString() string
ExpectString representation of mocked call.
func (*MockFindAll) Result ¶
func (mfa *MockFindAll) Result(result any) *Assert
Result sets the result of this query.
func (MockFindAll) String ¶
func (mfa MockFindAll) String() string
String representation of mocked call.
type MockFindAndCountAll ¶
type MockFindAndCountAll struct {
// contains filtered or unexported fields
}
MockFindAndCountAll asserts and simulate find and count all function for test.
func (*MockFindAndCountAll) ConnectionClosed ¶
func (mfca *MockFindAndCountAll) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.
func (*MockFindAndCountAll) Error ¶
func (mfca *MockFindAndCountAll) Error(err error) *Assert
Error sets error to be returned.
func (MockFindAndCountAll) ExpectString ¶
func (mfca MockFindAndCountAll) ExpectString() string
ExpectString representation of mocked call.
func (*MockFindAndCountAll) Result ¶
func (mfca *MockFindAndCountAll) Result(result any, count int) *Assert
Result sets the result of this query.
func (MockFindAndCountAll) String ¶
func (mfca MockFindAndCountAll) String() string
String representation of mocked call.
type MockInsertAll ¶
type MockInsertAll struct {
// contains filtered or unexported fields
}
MockInsertAll asserts and simulate Insert function for test.
func (*MockInsertAll) ConnectionClosed ¶
func (mia *MockInsertAll) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.
func (*MockInsertAll) Error ¶
func (mia *MockInsertAll) Error(err error) *Assert
Error sets error to be returned.
func (MockInsertAll) ExpectString ¶
func (mia MockInsertAll) ExpectString() string
ExpectString representation of mocked call.
func (*MockInsertAll) For ¶
func (mia *MockInsertAll) For(entity any) *MockInsertAll
For assert calls for given entity.
func (*MockInsertAll) ForTable ¶
func (mia *MockInsertAll) ForTable(typ string) *MockInsertAll
ForTable assert calls for given table.
func (*MockInsertAll) ForType ¶
func (mia *MockInsertAll) ForType(typ string) *MockInsertAll
ForType assert calls for given type. Type must include package name, example: `model.User`.
func (*MockInsertAll) NotUnique ¶
func (mia *MockInsertAll) NotUnique(key string) *Assert
NotUnique sets not unique error to be returned.
func (MockInsertAll) String ¶
func (mia MockInsertAll) String() string
String representation of mocked call.
func (*MockInsertAll) Success ¶
func (mia *MockInsertAll) Success() *Assert
Success sets no error to be returned.
type MockIterate ¶
type MockIterate struct {
// contains filtered or unexported fields
}
MockIterate asserts and simulate Delete function for test.
func (*MockIterate) ConnectionClosed ¶
func (mi *MockIterate) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.
func (*MockIterate) Error ¶
func (mi *MockIterate) Error(err error) *Assert
Error sets error to be returned.
func (MockIterate) ExpectString ¶
func (mi MockIterate) ExpectString() string
ExpectString representation of mocked call.
func (*MockIterate) Next ¶
func (mi *MockIterate) Next(entity any) error
Next return next entity in iterator.
func (*MockIterate) Result ¶
func (mi *MockIterate) Result(result any) *Assert
Result sets the result of preload.
func (MockIterate) String ¶
func (mi MockIterate) String() string
String representation of mocked call.
type MockMutate ¶
type MockMutate struct {
// contains filtered or unexported fields
}
MockMutate asserts and simulate Insert function for test.
func (*MockMutate) ConnectionClosed ¶
func (mm *MockMutate) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.
func (*MockMutate) Error ¶
func (mm *MockMutate) Error(err error) *Assert
Error sets error to be returned.
func (MockMutate) ExpectString ¶
func (mm MockMutate) ExpectString() string
ExpectString representation of mocked call.
func (*MockMutate) For ¶
func (mm *MockMutate) For(entity any) *MockMutate
For assert calls for given entity.
func (*MockMutate) ForContains ¶
func (mm *MockMutate) ForContains(contains any) *MockMutate
ForContains assert calls to contains some value of given struct.
func (*MockMutate) ForTable ¶
func (mm *MockMutate) ForTable(typ string) *MockMutate
ForTable assert calls for given table.
func (*MockMutate) ForType ¶
func (mm *MockMutate) ForType(typ string) *MockMutate
ForType assert calls for given type. Type must include package name, example: `model.User`.
func (*MockMutate) NotUnique ¶
func (mm *MockMutate) NotUnique(key string) *Assert
NotUnique sets not unique error to be returned.
func (MockMutate) String ¶
func (mm MockMutate) String() string
String representation of mocked call.
func (*MockMutate) Success ¶
func (mm *MockMutate) Success() *Assert
Success sets no error to be returned.
type MockPreload ¶
type MockPreload struct {
// contains filtered or unexported fields
}
MockPreload asserts and simulate Delete function for test.
func (*MockPreload) ConnectionClosed ¶
func (mp *MockPreload) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.
func (*MockPreload) Error ¶
func (mp *MockPreload) Error(err error) *Assert
Error sets error to be returned.
func (MockPreload) ExpectString ¶
func (mp MockPreload) ExpectString() string
ExpectString representation of mocked call.
func (*MockPreload) For ¶
func (md *MockPreload) For(entities any) *MockPreload
For assert calls for given entity.
func (*MockPreload) ForType ¶
func (md *MockPreload) ForType(typ string) *MockPreload
ForType assert calls for given type. Type must include package name, example: `model.User`.
func (*MockPreload) Result ¶
func (mp *MockPreload) Result(result any) *Assert
Result sets the result of preload.
func (MockPreload) String ¶
func (mp MockPreload) String() string
String representation of mocked call.
type MockUpdateAny ¶
type MockUpdateAny struct {
// contains filtered or unexported fields
}
MockUpdateAny asserts and simulate UpdateAny function for test.
func (*MockUpdateAny) ConnectionClosed ¶
func (mua *MockUpdateAny) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.
func (*MockUpdateAny) Error ¶
func (mua *MockUpdateAny) Error(err error) *Assert
Error sets error to be returned.
func (MockUpdateAny) ExpectString ¶
func (mua MockUpdateAny) ExpectString() string
ExpectString representation of mocked call.
func (MockUpdateAny) String ¶
func (mua MockUpdateAny) String() string
String representation of mocked call.
func (*MockUpdateAny) Unsafe ¶
func (mua *MockUpdateAny) Unsafe() *MockUpdateAny
Unsafe allows for unsafe operation to delete entities without where condition.
func (*MockUpdateAny) UpdatedCount ¶
func (mua *MockUpdateAny) UpdatedCount(updatedCount int) *Assert
UpdatedCount set the returned deleted count of this function.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository mock
func (*Repository) Adapter ¶
func (r *Repository) Adapter(ctx context.Context) rel.Adapter
Adapter provides a mock function with given fields:
func (*Repository) Aggregate ¶
func (r *Repository) Aggregate(ctx context.Context, query rel.Query, aggregate string, field string) (int, error)
Aggregate provides a mock function with given fields: query, aggregate, field
func (*Repository) AssertExpectations ¶
func (r *Repository) AssertExpectations(t TestingT) bool
AssertExpectations asserts that everything was in fact called as expected. Calls may have occurred in any order.
func (*Repository) Count ¶
func (r *Repository) Count(ctx context.Context, collection string, queriers ...rel.Querier) (int, error)
Count provides a mock function with given fields: collection, queriers
func (*Repository) DeleteAll ¶
func (r *Repository) DeleteAll(ctx context.Context, entities any) error
DeleteAll provides DeleteAll mock function with given fields: entities
func (*Repository) ExpectAggregate ¶
func (r *Repository) ExpectAggregate(query rel.Query, aggregate string, field string) *MockAggregate
ExpectAggregate apply mocks and expectations for Aggregate
func (*Repository) ExpectCount ¶
func (r *Repository) ExpectCount(collection string, queriers ...rel.Querier) *MockCount
ExpectCount apply mocks and expectations for Count
func (*Repository) ExpectDelete ¶
func (r *Repository) ExpectDelete(options ...rel.Mutator) *MockDelete
ExpectDelete apply mocks and expectations for Delete
func (*Repository) ExpectDeleteAll ¶
func (r *Repository) ExpectDeleteAll() *MockDeleteAll
ExpectDeleteAll apply mocks and expectations for DeleteAll
func (*Repository) ExpectDeleteAny ¶
func (r *Repository) ExpectDeleteAny(query rel.Query) *MockDeleteAny
ExpectDeleteAny apply mocks and expectations for DeleteAny
func (*Repository) ExpectExec ¶
func (r *Repository) ExpectExec(statement string, args ...any) *MockExec
ExpectExec for mocking Exec
func (*Repository) ExpectFind ¶
func (r *Repository) ExpectFind(queriers ...rel.Querier) *MockFind
ExpectFind apply mocks and expectations for Find
func (*Repository) ExpectFindAll ¶
func (r *Repository) ExpectFindAll(queriers ...rel.Querier) *MockFindAll
ExpectFindAll apply mocks and expectations for FindAll
func (*Repository) ExpectFindAndCountAll ¶
func (r *Repository) ExpectFindAndCountAll(queriers ...rel.Querier) *MockFindAndCountAll
ExpectFindAndCountAll apply mocks and expectations for FindAndCountAll
func (*Repository) ExpectInsert ¶
func (r *Repository) ExpectInsert(mutators ...rel.Mutator) *MockMutate
ExpectInsert apply mocks and expectations for Insert
func (*Repository) ExpectInsertAll ¶
func (r *Repository) ExpectInsertAll() *MockInsertAll
ExpectInsertAll entities.
func (*Repository) ExpectIterate ¶
func (r *Repository) ExpectIterate(query rel.Query, options ...rel.IteratorOption) *MockIterate
ExpectIterate apply mocks and expectations for Iterate
func (*Repository) ExpectPreload ¶
func (r *Repository) ExpectPreload(field string, queriers ...rel.Querier) *MockPreload
ExpectPreload apply mocks and expectations for Preload
func (*Repository) ExpectTransaction ¶
func (r *Repository) ExpectTransaction(fn func(*Repository))
ExpectTransaction declare expectation inside transaction.
func (*Repository) ExpectUpdate ¶
func (r *Repository) ExpectUpdate(mutators ...rel.Mutator) *MockMutate
ExpectUpdate apply mocks and expectations for Update
func (*Repository) ExpectUpdateAny ¶
func (r *Repository) ExpectUpdateAny(query rel.Query, mutates ...rel.Mutate) *MockUpdateAny
ExpectUpdateAny apply mocks and expectations for UpdateAny
func (*Repository) FindAndCountAll ¶
func (r *Repository) FindAndCountAll(ctx context.Context, entities any, queriers ...rel.Querier) (int, error)
FindAndCountAll provides a mock function with given fields: entities, queriers
func (*Repository) Instrumentation ¶
func (r *Repository) Instrumentation(instrumenter rel.Instrumenter)
Instrumentation provides a mock function with given fields: instrumenter
func (*Repository) Iterate ¶
func (r *Repository) Iterate(ctx context.Context, query rel.Query, options ...rel.IteratorOption) rel.Iterator
Iterate through a collection of entities from database in batches. This function returns iterator that can be used to loop all entities. Limit, Offset and Sort query is automatically ignored.
func (*Repository) MustAggregate ¶
func (r *Repository) MustAggregate(ctx context.Context, query rel.Query, aggregate string, field string) int
MustAggregate provides a mock function with given fields: query, aggregate, field
func (*Repository) MustCount ¶
MustCount provides a mock function with given fields: collection, queriers
func (*Repository) MustDelete ¶
func (r *Repository) MustDelete(ctx context.Context, entity any, options ...rel.Mutator)
MustDelete provides a mock function with given fields: entity
func (*Repository) MustDeleteAll ¶
func (r *Repository) MustDeleteAll(ctx context.Context, entity any)
MustDeleteAll provides a mock function with given fields: entity
func (*Repository) MustDeleteAny ¶
MustDeleteAny provides a mock function with given fields: query
func (*Repository) MustExec ¶
MustExec raw statement. Returns last inserted id, rows affected and error.
func (*Repository) MustFind ¶
func (r *Repository) MustFind(ctx context.Context, entity any, queriers ...rel.Querier)
MustFind provides a mock function with given fields: entity, queriers
func (*Repository) MustFindAll ¶
func (r *Repository) MustFindAll(ctx context.Context, entities any, queriers ...rel.Querier)
MustFindAll provides a mock function with given fields: entities, queriers
func (*Repository) MustFindAndCountAll ¶
func (r *Repository) MustFindAndCountAll(ctx context.Context, entities any, queriers ...rel.Querier) int
MustFindAndCountAll provides a mock function with given fields: entities, queriers
func (*Repository) MustInsert ¶
func (r *Repository) MustInsert(ctx context.Context, entity any, mutators ...rel.Mutator)
MustInsert provides a mock function with given fields: entity, mutators
func (*Repository) MustInsertAll ¶
func (r *Repository) MustInsertAll(ctx context.Context, entities any, mutators ...rel.Mutator)
MustInsertAll entities.
func (*Repository) MustPreload ¶
func (r *Repository) MustPreload(ctx context.Context, entities any, field string, queriers ...rel.Querier)
MustPreload provides a mock function with given fields: entities, field, queriers
func (*Repository) MustUpdate ¶
func (r *Repository) MustUpdate(ctx context.Context, entity any, mutators ...rel.Mutator)
MustUpdate provides a mock function with given fields: entity, mutators
func (*Repository) MustUpdateAny ¶
MustUpdateAny provides a mock function with given fields: query
func (*Repository) Preload ¶
func (r *Repository) Preload(ctx context.Context, entities any, field string, queriers ...rel.Querier) error
Preload provides a mock function with given fields: entities, field, queriers
func (*Repository) Transaction ¶
Transaction provides a mock function with given fields: fn
Source Files ¶
- aggregate.go
- any_notgo1.18.go
- assert.go
- context.go
- count.go
- delete.go
- delete_all.go
- delete_any.go
- entity_delete_all_go1.18.go
- entity_delete_go1.18.go
- entity_find_all_go1.18.go
- entity_find_and_count_all_go1.18.go
- entity_find_go1.18.go
- entity_insert_all_go1.18.go
- entity_iterate_go1.18.go
- entity_mutate_go1.18.go
- entity_preload_all_go1.18.go
- entity_preload_go1.18.go
- entity_repository_go1.18.go
- exec.go
- find.go
- find_all.go
- find_and_count_all.go
- insert_all.go
- iterate.go
- match.go
- mutate.go
- nop_adapter.go
- preload.go
- reltest.go
- repository.go
- update_any.go
- util.go