Skip to content

reltest

import "github.com/go-rel/reltest"

Overview

Package reltest for unit testing database interaction.

Variables

var Any interface{} = any{}
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()
Many set max calls to unlimited times.

func (*Assert) Maybe

func (a *Assert) Maybe()
Maybe allow calls to be skipped.

func (*Assert) Once

func (a *Assert) Once()
Once set max calls to one time.

func (*Assert) Times

func (a *Assert) Times(times int)
Times set number of allowed calls.

func (*Assert) Twice

func (a *Assert) Twice()
Twice set max calls to two times.

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

func (mc *MockCount) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.

func (*MockCount) Error

func (mc *MockCount) Error(err error) *Assert
Error sets error to be returned.

func (MockCount) ExpectString

func (mc MockCount) ExpectString() string
ExpectString representation of mocked call.

func (*MockCount) Result

func (mc *MockCount) Result(count int) *Assert
Result sets the result of this query.

func (MockCount) String

func (mc MockCount) String() string
String 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(record interface{}) *MockDelete
For assert calls for given record.

func (*MockDelete) ForContains

func (md *MockDelete) ForContains(contains interface{}) *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(record interface{}) *MockDeleteAll
For assert calls for given record.

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 records without where condition.

type MockExec

type MockExec struct {
    // contains filtered or unexported fields
}
MockExec asserts and simulate UpdateAny function for test.

func (*MockExec) ConnectionClosed

func (me *MockExec) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.

func (*MockExec) Error

func (me *MockExec) Error(err error) *Assert
Error sets error to be returned.

func (MockExec) ExpectString

func (me MockExec) ExpectString() string
ExpectString representation of mocked call.

func (*MockExec) Result

func (me *MockExec) Result(lastInsertedId int, rowsAffected int) *Assert
Result sets the result of this query.

func (MockExec) String

func (me MockExec) String() string
String 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

func (mf *MockFind) ConnectionClosed() *Assert
ConnectionClosed sets this error to be returned.

func (*MockFind) Error

func (mf *MockFind) Error(err error) *Assert
Error sets error to be returned.

func (MockFind) ExpectString

func (mf MockFind) ExpectString() string
ExpectString representation of mocked call.

func (*MockFind) NotFound

func (mf *MockFind) NotFound() *Assert
NotFound sets NotFoundError to be returned.

func (*MockFind) Result

func (mf *MockFind) Result(result interface{}) *Assert
Result sets the result of this query.

func (MockFind) String

func (mf MockFind) String() string
String 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 interface{}) *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 interface{}, 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(record interface{}) *MockInsertAll
For assert calls for given record.

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) Close

func (mi MockIterate) Close() error

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(record interface{}) error

func (*MockIterate) Result

func (mi *MockIterate) Result(result interface{}) *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(record interface{}) *MockMutate
For assert calls for given record.

func (*MockMutate) ForContains

func (mm *MockMutate) ForContains(contains interface{}) *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(records interface{}) *MockPreload
For assert calls for given record.

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 interface{}) *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 records 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 is an autogenerated mock type for the Repository type

func New

func New() *Repository
New test repository.

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 T) 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) Delete

func (r *Repository) Delete(ctx context.Context, record interface{}, options ...rel.Mutator) error
Delete provides a mock function with given fields: record

func (*Repository) DeleteAll

func (r *Repository) DeleteAll(ctx context.Context, records interface{}) error
DeleteAll provides DeleteAll mock function with given fields: records

func (*Repository) DeleteAny

func (r *Repository) DeleteAny(ctx context.Context, query rel.Query) (int, error)
DeleteAny provides a mock function with given fields: query

func (*Repository) Exec

func (r *Repository) Exec(ctx context.Context, statement string, args ...interface{}) (int, int, error)
Exec raw statement. Returns last inserted id, rows affected and error.

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 ...interface{}) *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 records.

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) Find

func (r *Repository) Find(ctx context.Context, record interface{}, queriers ...rel.Querier) error
Find provides a mock function with given fields: record, queriers

func (*Repository) FindAll

func (r *Repository) FindAll(ctx context.Context, records interface{}, queriers ...rel.Querier) error
FindAll provides a mock function with given fields: records, queriers

func (*Repository) FindAndCountAll

func (r *Repository) FindAndCountAll(ctx context.Context, records interface{}, queriers ...rel.Querier) (int, error)
FindAndCountAll provides a mock function with given fields: records, queriers

func (*Repository) Insert

func (r *Repository) Insert(ctx context.Context, record interface{}, mutators ...rel.Mutator) error
Insert provides a mock function with given fields: record, mutators

func (*Repository) InsertAll

func (r *Repository) InsertAll(ctx context.Context, records interface{}, mutators ...rel.Mutator) error
InsertAll records.

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 records from database in batches. This function returns iterator that can be used to loop all records. 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

func (r *Repository) MustCount(ctx context.Context, collection string, queriers ...rel.Querier) int
MustCount provides a mock function with given fields: collection, queriers

func (*Repository) MustDelete

func (r *Repository) MustDelete(ctx context.Context, record interface{}, options ...rel.Mutator)
MustDelete provides a mock function with given fields: record

func (*Repository) MustDeleteAll

func (r *Repository) MustDeleteAll(ctx context.Context, record interface{})
MustDeleteAll provides a mock function with given fields: record

func (*Repository) MustDeleteAny

func (r *Repository) MustDeleteAny(ctx context.Context, query rel.Query) int
MustDeleteAny provides a mock function with given fields: query

func (*Repository) MustExec

func (r *Repository) MustExec(ctx context.Context, statement string, args ...interface{}) (int, int)
MustExec raw statement. Returns last inserted id, rows affected and error.

func (*Repository) MustFind

func (r *Repository) MustFind(ctx context.Context, record interface{}, queriers ...rel.Querier)
MustFind provides a mock function with given fields: record, queriers

func (*Repository) MustFindAll

func (r *Repository) MustFindAll(ctx context.Context, records interface{}, queriers ...rel.Querier)
MustFindAll provides a mock function with given fields: records, queriers

func (*Repository) MustFindAndCountAll

func (r *Repository) MustFindAndCountAll(ctx context.Context, records interface{}, queriers ...rel.Querier) int
MustFindAndCountAll provides a mock function with given fields: records, queriers

func (*Repository) MustInsert

func (r *Repository) MustInsert(ctx context.Context, record interface{}, mutators ...rel.Mutator)
MustInsert provides a mock function with given fields: record, mutators

func (*Repository) MustInsertAll

func (r *Repository) MustInsertAll(ctx context.Context, records interface{}, mutators ...rel.Mutator)
MustInsertAll records.

func (*Repository) MustPreload

func (r *Repository) MustPreload(ctx context.Context, records interface{}, field string, queriers ...rel.Querier)
MustPreload provides a mock function with given fields: records, field, queriers

func (*Repository) MustUpdate

func (r *Repository) MustUpdate(ctx context.Context, record interface{}, mutators ...rel.Mutator)
MustUpdate provides a mock function with given fields: record, mutators

func (*Repository) MustUpdateAny

func (r *Repository) MustUpdateAny(ctx context.Context, query rel.Query, mutates ...rel.Mutate) int
MustUpdateAny provides a mock function with given fields: query

func (*Repository) Ping

func (r *Repository) Ping(ctx context.Context) error
Ping database.

func (*Repository) Preload

func (r *Repository) Preload(ctx context.Context, records interface{}, field string, queriers ...rel.Querier) error
Preload provides a mock function with given fields: records, field, queriers

func (*Repository) Transaction

func (r *Repository) Transaction(ctx context.Context, fn func(ctx context.Context) error) error
Transaction provides a mock function with given fields: fn

func (*Repository) Update

func (r *Repository) Update(ctx context.Context, record interface{}, mutators ...rel.Mutator) error
Update provides a mock function with given fields: record, mutators

func (*Repository) UpdateAny

func (r *Repository) UpdateAny(ctx context.Context, query rel.Query, mutates ...rel.Mutate) (int, error)
UpdateAny provides a mock function with given fields: query

type T

type T interface {
    Logf(format string, args ...interface{})
    Errorf(format string, args ...interface{})
    Helper()
}
T is an interface wrapper around *testing.T


Last update: 2022-06-25