reltest¶
import "github.com/go-rel/reltest"
Overview¶
Package reltest for unit testing database interaction.
Variables¶
var Any any = anyValue{}
var (
// ErrConnectionClosed is alias for sql.ErrConnDone.
ErrConnectionClosed = sql.ErrConnDone
)
type Assert¶
type Assert struct {
// contains filtered or unexported fields
}
func (*Assert) Many¶
func (a *Assert) Many()
func (*Assert) Maybe¶
func (a *Assert) Maybe()
func (*Assert) Once¶
func (a *Assert) Once()
func (*Assert) Times¶
func (a *Assert) Times(times int)
func (*Assert) Twice¶
func (a *Assert) Twice()
type EntityMockDelete¶
type EntityMockDelete[T any] struct {
*MockDelete
}
func (*EntityMockDelete[T]) For¶
func (emd *EntityMockDelete[T]) For(result *T) *EntityMockDelete[T]
type EntityMockDeleteAll¶
type EntityMockDeleteAll[T any] struct {
*MockDeleteAll
}
func (*EntityMockDeleteAll[T]) For¶
func (emda *EntityMockDeleteAll[T]) For(result *[]T) *EntityMockDeleteAll[T]
type EntityMockFind¶
type EntityMockFind[T any] struct {
*MockFind
}
func (*EntityMockFind[T]) Result¶
func (emf *EntityMockFind[T]) Result(result T) *Assert
type EntityMockFindAll¶
type EntityMockFindAll[T any] struct {
*MockFindAll
}
func (*EntityMockFindAll[T]) Result¶
func (emfa *EntityMockFindAll[T]) Result(result []T) *Assert
type EntityMockFindAndCountAll¶
type EntityMockFindAndCountAll[T any] struct {
*MockFindAndCountAll
}
func (*EntityMockFindAndCountAll[T]) Result¶
func (emfaca *EntityMockFindAndCountAll[T]) Result(result []T, count int) *Assert
type EntityMockInsertAll¶
type EntityMockInsertAll[T any] struct {
*MockInsertAll
}
func (*EntityMockInsertAll[T]) For¶
func (emia *EntityMockInsertAll[T]) For(result *[]T) *EntityMockInsertAll[T]
type EntityMockIterate¶
type EntityMockIterate[T any] struct {
*MockIterate
}
func (*EntityMockIterate[T]) Result¶
func (emi *EntityMockIterate[T]) Result(result []T) *Assert
type EntityMockMutate¶
type EntityMockMutate[T any] struct {
*MockMutate
}
func (*EntityMockMutate[T]) For¶
func (emm *EntityMockMutate[T]) For(result *T) *EntityMockMutate[T]
type EntityMockPreload¶
type EntityMockPreload[T any] struct {
*MockPreload
}
func (*EntityMockPreload[T]) For¶
func (emp *EntityMockPreload[T]) For(result *T) *EntityMockPreload[T]
type EntityMockPreloadAll¶
type EntityMockPreloadAll[T any] struct {
*MockPreload
}
func (*EntityMockPreloadAll[T]) For¶
func (empa *EntityMockPreloadAll[T]) For(result *[]T) *EntityMockPreloadAll[T]
type EntityRepository¶
type EntityRepository[T any] struct {
rel.EntityRepository[T]
// contains filtered or unexported fields
}
func NewEntityRepository¶
func NewEntityRepository[T any]() *EntityRepository[T]
func (*EntityRepository[T]) AssertExpectations¶
func (er *EntityRepository[T]) AssertExpectations(t TestingT) bool
func (*EntityRepository[T]) ExpectAggregate¶
func (er *EntityRepository[T]) ExpectAggregate(query rel.Query, aggregate string, field string) *MockAggregate
func (*EntityRepository[T]) ExpectCount¶
func (er *EntityRepository[T]) ExpectCount(collection string, queriers ...rel.Querier) *MockCount
func (*EntityRepository[T]) ExpectDelete¶
func (er *EntityRepository[T]) ExpectDelete(options ...rel.Mutator) *EntityMockDelete[T]
func (*EntityRepository[T]) ExpectDeleteAll¶
func (er *EntityRepository[T]) ExpectDeleteAll() *EntityMockDeleteAll[T]
func (*EntityRepository[T]) ExpectFind¶
func (er *EntityRepository[T]) ExpectFind(queriers ...rel.Querier) *EntityMockFind[T]
func (*EntityRepository[T]) ExpectFindAll¶
func (er *EntityRepository[T]) ExpectFindAll(queriers ...rel.Querier) *EntityMockFindAll[T]
func (*EntityRepository[T]) ExpectFindAndCountAll¶
func (er *EntityRepository[T]) ExpectFindAndCountAll(queriers ...rel.Querier) *EntityMockFindAndCountAll[T]
func (*EntityRepository[T]) ExpectInsert¶
func (er *EntityRepository[T]) ExpectInsert(mutators ...rel.Mutator) *EntityMockMutate[T]
func (*EntityRepository[T]) ExpectInsertAll¶
func (er *EntityRepository[T]) ExpectInsertAll() *EntityMockInsertAll[T]
func (*EntityRepository[T]) ExpectIterate¶
func (er *EntityRepository[T]) ExpectIterate(query rel.Query, options ...rel.IteratorOption) *EntityMockIterate[T]
func (*EntityRepository[T]) ExpectPreload¶
func (er *EntityRepository[T]) ExpectPreload(field string, queriers ...rel.Querier) *EntityMockPreload[T]
func (*EntityRepository[T]) ExpectPreloadAll¶
func (er *EntityRepository[T]) ExpectPreloadAll(field string, queriers ...rel.Querier) *EntityMockPreloadAll[T]
func (*EntityRepository[T]) ExpectTransaction¶
func (er *EntityRepository[T]) ExpectTransaction(fn func(*Repository))
func (*EntityRepository[T]) ExpectUpdate¶
func (er *EntityRepository[T]) ExpectUpdate(mutators ...rel.Mutator) *EntityMockMutate[T]
func (*EntityRepository[T]) WrapTransaction¶
func (er *EntityRepository[T]) WrapTransaction(repository *Repository) *EntityRepository[T]
type MockAggregate¶
type MockAggregate struct {
// contains filtered or unexported fields
}
func (*MockAggregate) ConnectionClosed¶
func (ma *MockAggregate) ConnectionClosed() *Assert
func (*MockAggregate) Error¶
func (ma *MockAggregate) Error(err error) *Assert
func (MockAggregate) ExpectString¶
func (ma MockAggregate) ExpectString() string
func (*MockAggregate) Result¶
func (ma *MockAggregate) Result(count int) *Assert
func (MockAggregate) String¶
func (ma MockAggregate) String() string
type MockCount¶
type MockCount struct {
// contains filtered or unexported fields
}
func (*MockCount) ConnectionClosed¶
func (mc *MockCount) ConnectionClosed() *Assert
func (*MockCount) Error¶
func (mc *MockCount) Error(err error) *Assert
func (MockCount) ExpectString¶
func (mc MockCount) ExpectString() string
func (*MockCount) Result¶
func (mc *MockCount) Result(count int) *Assert
func (MockCount) String¶
func (mc MockCount) String() string
type MockDelete¶
type MockDelete struct {
// contains filtered or unexported fields
}
func (*MockDelete) ConnectionClosed¶
func (md *MockDelete) ConnectionClosed() *Assert
func (*MockDelete) Error¶
func (md *MockDelete) Error(err error) *Assert
func (MockDelete) ExpectString¶
func (md MockDelete) ExpectString() string
func (*MockDelete) For¶
func (md *MockDelete) For(entity any) *MockDelete
func (*MockDelete) ForContains¶
func (md *MockDelete) ForContains(contains any) *MockDelete
func (*MockDelete) ForTable¶
func (md *MockDelete) ForTable(typ string) *MockDelete
func (*MockDelete) ForType¶
func (md *MockDelete) ForType(typ string) *MockDelete
model.User
. func (MockDelete) String¶
func (md MockDelete) String() string
func (*MockDelete) Success¶
func (md *MockDelete) Success() *Assert
type MockDeleteAll¶
type MockDeleteAll struct {
// contains filtered or unexported fields
}
func (*MockDeleteAll) ConnectionClosed¶
func (mda *MockDeleteAll) ConnectionClosed() *Assert
func (*MockDeleteAll) Error¶
func (mda *MockDeleteAll) Error(err error) *Assert
func (MockDeleteAll) ExpectString¶
func (mda MockDeleteAll) ExpectString() string
func (*MockDeleteAll) For¶
func (mda *MockDeleteAll) For(entity any) *MockDeleteAll
func (*MockDeleteAll) ForTable¶
func (mda *MockDeleteAll) ForTable(typ string) *MockDeleteAll
func (*MockDeleteAll) ForType¶
func (mda *MockDeleteAll) ForType(typ string) *MockDeleteAll
model.User
. func (MockDeleteAll) String¶
func (mda MockDeleteAll) String() string
func (*MockDeleteAll) Success¶
func (mda *MockDeleteAll) Success() *Assert
type MockDeleteAny¶
type MockDeleteAny struct {
// contains filtered or unexported fields
}
func (*MockDeleteAny) ConnectionClosed¶
func (mda *MockDeleteAny) ConnectionClosed() *Assert
func (*MockDeleteAny) DeletedCount¶
func (mda *MockDeleteAny) DeletedCount(deletedCount int) *Assert
func (*MockDeleteAny) Error¶
func (mda *MockDeleteAny) Error(err error) *Assert
func (MockDeleteAny) ExpectString¶
func (mda MockDeleteAny) ExpectString() string
func (MockDeleteAny) String¶
func (mda MockDeleteAny) String() string
func (*MockDeleteAny) Success¶
func (mda *MockDeleteAny) Success() *Assert
func (*MockDeleteAny) Unsafe¶
func (mda *MockDeleteAny) Unsafe() *MockDeleteAny
type MockExec¶
type MockExec struct {
// contains filtered or unexported fields
}
func (*MockExec) ConnectionClosed¶
func (me *MockExec) ConnectionClosed() *Assert
func (*MockExec) Error¶
func (me *MockExec) Error(err error) *Assert
func (MockExec) ExpectString¶
func (me MockExec) ExpectString() string
func (*MockExec) Result¶
func (me *MockExec) Result(lastInsertedId int, rowsAffected int) *Assert
func (MockExec) String¶
func (me MockExec) String() string
type MockFind¶
type MockFind struct {
// contains filtered or unexported fields
}
func (*MockFind) ConnectionClosed¶
func (mf *MockFind) ConnectionClosed() *Assert
func (*MockFind) Error¶
func (mf *MockFind) Error(err error) *Assert
func (MockFind) ExpectString¶
func (mf MockFind) ExpectString() string
func (*MockFind) NotFound¶
func (mf *MockFind) NotFound() *Assert
func (*MockFind) Result¶
func (mf *MockFind) Result(result any) *Assert
func (MockFind) String¶
func (mf MockFind) String() string
type MockFindAll¶
type MockFindAll struct {
// contains filtered or unexported fields
}
func (*MockFindAll) ConnectionClosed¶
func (mfa *MockFindAll) ConnectionClosed() *Assert
func (*MockFindAll) Error¶
func (mfa *MockFindAll) Error(err error) *Assert
func (MockFindAll) ExpectString¶
func (mfa MockFindAll) ExpectString() string
func (*MockFindAll) Result¶
func (mfa *MockFindAll) Result(result any) *Assert
func (MockFindAll) String¶
func (mfa MockFindAll) String() string
type MockFindAndCountAll¶
type MockFindAndCountAll struct {
// contains filtered or unexported fields
}
func (*MockFindAndCountAll) ConnectionClosed¶
func (mfca *MockFindAndCountAll) ConnectionClosed() *Assert
func (*MockFindAndCountAll) Error¶
func (mfca *MockFindAndCountAll) Error(err error) *Assert
func (MockFindAndCountAll) ExpectString¶
func (mfca MockFindAndCountAll) ExpectString() string
func (*MockFindAndCountAll) Result¶
func (mfca *MockFindAndCountAll) Result(result any, count int) *Assert
func (MockFindAndCountAll) String¶
func (mfca MockFindAndCountAll) String() string
type MockInsertAll¶
type MockInsertAll struct {
// contains filtered or unexported fields
}
func (*MockInsertAll) ConnectionClosed¶
func (mia *MockInsertAll) ConnectionClosed() *Assert
func (*MockInsertAll) Error¶
func (mia *MockInsertAll) Error(err error) *Assert
func (MockInsertAll) ExpectString¶
func (mia MockInsertAll) ExpectString() string
func (*MockInsertAll) For¶
func (mia *MockInsertAll) For(entity any) *MockInsertAll
func (*MockInsertAll) ForTable¶
func (mia *MockInsertAll) ForTable(typ string) *MockInsertAll
func (*MockInsertAll) ForType¶
func (mia *MockInsertAll) ForType(typ string) *MockInsertAll
model.User
. func (*MockInsertAll) NotUnique¶
func (mia *MockInsertAll) NotUnique(key string) *Assert
func (MockInsertAll) String¶
func (mia MockInsertAll) String() string
func (*MockInsertAll) Success¶
func (mia *MockInsertAll) Success() *Assert
type MockIterate¶
type MockIterate struct {
// contains filtered or unexported fields
}
func (MockIterate) Close¶
func (mi MockIterate) Close() error
func (*MockIterate) ConnectionClosed¶
func (mi *MockIterate) ConnectionClosed() *Assert
func (*MockIterate) Error¶
func (mi *MockIterate) Error(err error) *Assert
func (MockIterate) ExpectString¶
func (mi MockIterate) ExpectString() string
func (*MockIterate) Next¶
func (mi *MockIterate) Next(entity any) error
func (*MockIterate) Result¶
func (mi *MockIterate) Result(result any) *Assert
func (MockIterate) String¶
func (mi MockIterate) String() string
type MockMutate¶
type MockMutate struct {
// contains filtered or unexported fields
}
func (*MockMutate) ConnectionClosed¶
func (mm *MockMutate) ConnectionClosed() *Assert
func (*MockMutate) Error¶
func (mm *MockMutate) Error(err error) *Assert
func (MockMutate) ExpectString¶
func (mm MockMutate) ExpectString() string
func (*MockMutate) For¶
func (mm *MockMutate) For(entity any) *MockMutate
func (*MockMutate) ForContains¶
func (mm *MockMutate) ForContains(contains any) *MockMutate
func (*MockMutate) ForTable¶
func (mm *MockMutate) ForTable(typ string) *MockMutate
func (*MockMutate) ForType¶
func (mm *MockMutate) ForType(typ string) *MockMutate
model.User
. func (*MockMutate) NotUnique¶
func (mm *MockMutate) NotUnique(key string) *Assert
func (MockMutate) String¶
func (mm MockMutate) String() string
func (*MockMutate) Success¶
func (mm *MockMutate) Success() *Assert
type MockPreload¶
type MockPreload struct {
// contains filtered or unexported fields
}
func (*MockPreload) ConnectionClosed¶
func (mp *MockPreload) ConnectionClosed() *Assert
func (*MockPreload) Error¶
func (mp *MockPreload) Error(err error) *Assert
func (MockPreload) ExpectString¶
func (mp MockPreload) ExpectString() string
func (*MockPreload) For¶
func (md *MockPreload) For(entities any) *MockPreload
func (*MockPreload) ForType¶
func (md *MockPreload) ForType(typ string) *MockPreload
model.User
. func (*MockPreload) Result¶
func (mp *MockPreload) Result(result any) *Assert
func (MockPreload) String¶
func (mp MockPreload) String() string
type MockUpdateAny¶
type MockUpdateAny struct {
// contains filtered or unexported fields
}
func (*MockUpdateAny) ConnectionClosed¶
func (mua *MockUpdateAny) ConnectionClosed() *Assert
func (*MockUpdateAny) Error¶
func (mua *MockUpdateAny) Error(err error) *Assert
func (MockUpdateAny) ExpectString¶
func (mua MockUpdateAny) ExpectString() string
func (MockUpdateAny) String¶
func (mua MockUpdateAny) String() string
func (*MockUpdateAny) Unsafe¶
func (mua *MockUpdateAny) Unsafe() *MockUpdateAny
func (*MockUpdateAny) UpdatedCount¶
func (mua *MockUpdateAny) UpdatedCount(updatedCount int) *Assert
type Repository¶
type Repository struct {
// contains filtered or unexported fields
}
func New¶
func New() *Repository
func (*Repository) Adapter¶
func (r *Repository) Adapter(ctx context.Context) rel.Adapter
func (*Repository) Aggregate¶
func (r *Repository) Aggregate(ctx context.Context, query rel.Query, aggregate string, field string) (int, error)
func (*Repository) AssertExpectations¶
func (r *Repository) AssertExpectations(t TestingT) bool
func (*Repository) Count¶
func (r *Repository) Count(ctx context.Context, collection string, queriers ...rel.Querier) (int, error)
func (*Repository) Delete¶
func (r *Repository) Delete(ctx context.Context, entity any, options ...rel.Mutator) error
func (*Repository) DeleteAll¶
func (r *Repository) DeleteAll(ctx context.Context, entities any) error
func (*Repository) DeleteAny¶
func (r *Repository) DeleteAny(ctx context.Context, query rel.Query) (int, error)
func (*Repository) Exec¶
func (r *Repository) Exec(ctx context.Context, statement string, args ...any) (int, int, error)
func (*Repository) ExpectAggregate¶
func (r *Repository) ExpectAggregate(query rel.Query, aggregate string, field string) *MockAggregate
func (*Repository) ExpectCount¶
func (r *Repository) ExpectCount(collection string, queriers ...rel.Querier) *MockCount
func (*Repository) ExpectDelete¶
func (r *Repository) ExpectDelete(options ...rel.Mutator) *MockDelete
func (*Repository) ExpectDeleteAll¶
func (r *Repository) ExpectDeleteAll() *MockDeleteAll
func (*Repository) ExpectDeleteAny¶
func (r *Repository) ExpectDeleteAny(query rel.Query) *MockDeleteAny
func (*Repository) ExpectExec¶
func (r *Repository) ExpectExec(statement string, args ...any) *MockExec
func (*Repository) ExpectFind¶
func (r *Repository) ExpectFind(queriers ...rel.Querier) *MockFind
func (*Repository) ExpectFindAll¶
func (r *Repository) ExpectFindAll(queriers ...rel.Querier) *MockFindAll
func (*Repository) ExpectFindAndCountAll¶
func (r *Repository) ExpectFindAndCountAll(queriers ...rel.Querier) *MockFindAndCountAll
func (*Repository) ExpectInsert¶
func (r *Repository) ExpectInsert(mutators ...rel.Mutator) *MockMutate
func (*Repository) ExpectInsertAll¶
func (r *Repository) ExpectInsertAll() *MockInsertAll
func (*Repository) ExpectIterate¶
func (r *Repository) ExpectIterate(query rel.Query, options ...rel.IteratorOption) *MockIterate
func (*Repository) ExpectPreload¶
func (r *Repository) ExpectPreload(field string, queriers ...rel.Querier) *MockPreload
func (*Repository) ExpectTransaction¶
func (r *Repository) ExpectTransaction(fn func(*Repository))
func (*Repository) ExpectUpdate¶
func (r *Repository) ExpectUpdate(mutators ...rel.Mutator) *MockMutate
func (*Repository) ExpectUpdateAny¶
func (r *Repository) ExpectUpdateAny(query rel.Query, mutates ...rel.Mutate) *MockUpdateAny
func (*Repository) Find¶
func (r *Repository) Find(ctx context.Context, entity any, queriers ...rel.Querier) error
func (*Repository) FindAll¶
func (r *Repository) FindAll(ctx context.Context, entities any, queriers ...rel.Querier) error
func (*Repository) FindAndCountAll¶
func (r *Repository) FindAndCountAll(ctx context.Context, entities any, queriers ...rel.Querier) (int, error)
func (*Repository) Insert¶
func (r *Repository) Insert(ctx context.Context, entity any, mutators ...rel.Mutator) error
func (*Repository) InsertAll¶
func (r *Repository) InsertAll(ctx context.Context, entities any, mutators ...rel.Mutator) error
func (*Repository) Instrumentation¶
func (r *Repository) Instrumentation(instrumenter rel.Instrumenter)
func (*Repository) Iterate¶
func (r *Repository) Iterate(ctx context.Context, query rel.Query, options ...rel.IteratorOption) rel.Iterator
func (*Repository) MustAggregate¶
func (r *Repository) MustAggregate(ctx context.Context, query rel.Query, aggregate string, field string) int
func (*Repository) MustCount¶
func (r *Repository) MustCount(ctx context.Context, collection string, queriers ...rel.Querier) int
func (*Repository) MustDelete¶
func (r *Repository) MustDelete(ctx context.Context, entity any, options ...rel.Mutator)
func (*Repository) MustDeleteAll¶
func (r *Repository) MustDeleteAll(ctx context.Context, entity any)
func (*Repository) MustDeleteAny¶
func (r *Repository) MustDeleteAny(ctx context.Context, query rel.Query) int
func (*Repository) MustExec¶
func (r *Repository) MustExec(ctx context.Context, statement string, args ...any) (int, int)
func (*Repository) MustFind¶
func (r *Repository) MustFind(ctx context.Context, entity any, queriers ...rel.Querier)
func (*Repository) MustFindAll¶
func (r *Repository) MustFindAll(ctx context.Context, entities any, queriers ...rel.Querier)
func (*Repository) MustFindAndCountAll¶
func (r *Repository) MustFindAndCountAll(ctx context.Context, entities any, queriers ...rel.Querier) int
func (*Repository) MustInsert¶
func (r *Repository) MustInsert(ctx context.Context, entity any, mutators ...rel.Mutator)
func (*Repository) MustInsertAll¶
func (r *Repository) MustInsertAll(ctx context.Context, entities any, mutators ...rel.Mutator)
func (*Repository) MustPreload¶
func (r *Repository) MustPreload(ctx context.Context, entities any, field string, queriers ...rel.Querier)
func (*Repository) MustUpdate¶
func (r *Repository) MustUpdate(ctx context.Context, entity any, mutators ...rel.Mutator)
func (*Repository) MustUpdateAny¶
func (r *Repository) MustUpdateAny(ctx context.Context, query rel.Query, mutates ...rel.Mutate) int
func (*Repository) Ping¶
func (r *Repository) Ping(ctx context.Context) error
func (*Repository) Preload¶
func (r *Repository) Preload(ctx context.Context, entities any, field string, queriers ...rel.Querier) error
func (*Repository) Transaction¶
func (r *Repository) Transaction(ctx context.Context, fn func(ctx context.Context) error) error
func (*Repository) Update¶
func (r *Repository) Update(ctx context.Context, entity any, mutators ...rel.Mutator) error
func (*Repository) UpdateAny¶
func (r *Repository) UpdateAny(ctx context.Context, query rel.Query, mutates ...rel.Mutate) (int, error)
type TestingT¶
type TestingT interface {
Logf(format string, args ...any)
Errorf(format string, args ...any)
Helper()
}
Last update: 2024-12-19