reltest

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConnectionClosed is alias for sql.ErrConnDone.
	ErrConnectionClosed = sql.ErrConnDone
)

Functions

This section is empty.

Types

type Aggregate

type Aggregate struct {
	*Expect
}

Aggregate asserts and simulate aggregate function for test.

func ExpectAggregate

func ExpectAggregate(r *Repository, query rel.Query, aggregate string, field string) *Aggregate

ExpectAggregate to be called with given field and queries.

func ExpectCount

func ExpectCount(r *Repository, collection string, queriers []rel.Querier) *Aggregate

ExpectCount to be called with given field and queries.

func (*Aggregate) ConnectionClosed

func (a *Aggregate) ConnectionClosed()

ConnectionClosed sets this error to be returned.

func (*Aggregate) Error

func (a *Aggregate) Error(err error)

Error sets error to be returned.

func (*Aggregate) Result

func (a *Aggregate) Result(count int)

Result sets the result of this query.

type Delete

type Delete struct {
	*Expect
}

Delete asserts and simulate delete function for test.

func ExpectDelete

func ExpectDelete(r *Repository, options []rel.Cascade) *Delete

ExpectDelete to be called.

func ExpectDeleteAll

func ExpectDeleteAll(r *Repository) *Delete

ExpectDeleteAll to be called.

func (*Delete) For

func (d *Delete) For(record interface{}) *Delete

For match expect calls for given record.

func (*Delete) ForType

func (d *Delete) ForType(typ string) *Delete

ForType match expect calls for given type. Type must include package name, example: `model.User`.

type Exec added in v0.14.0

type Exec struct {
	*Expect
}

Exec asserts and simulate exec function for test.

func ExpectExec added in v0.14.0

func ExpectExec(r *Repository, statement string, args []interface{}) *Exec

ExpectExec to be called with given field and queries.

func (*Exec) ConnectionClosed added in v0.14.0

func (e *Exec) ConnectionClosed()

ConnectionClosed sets this error to be returned.

func (*Exec) Error added in v0.14.0

func (e *Exec) Error(err error)

Error sets error to be returned.

func (*Exec) Result added in v0.14.0

func (e *Exec) Result(lastInsertedId int, rowsAffected int)

Result sets the result of this query.

type Expect

type Expect struct {
	*mock.Call
}

Expect is base behaviour for all reltest expectations.

func (*Expect) ConnectionClosed

func (e *Expect) ConnectionClosed()

ConnectionClosed sets this error to be returned.

func (*Expect) Error

func (e *Expect) Error(err error)

Error sets error to be returned.

type Find

type Find struct {
	*FindAll
}

Find asserts and simulate find function for test.

func ExpectFind

func ExpectFind(r *Repository, queriers []rel.Querier) *Find

ExpectFind to be called with given field and queries.

func (*Find) NotFound

func (f *Find) NotFound()

NotFound sets NotFoundError to be returned.

type FindAll

type FindAll struct {
	*Expect
}

FindAll asserts and simulate find all function for test.

func ExpectFindAll

func ExpectFindAll(r *Repository, queriers []rel.Querier) *FindAll

ExpectFindAll to be called with given field and queries.

func (*FindAll) Result

func (fa *FindAll) Result(records interface{})

Result sets the result of this query.

type FindAndCountAll

type FindAndCountAll struct {
	*Expect
}

FindAndCountAll asserts and simulate find all function for test.

func ExpectFindAndCountAll

func ExpectFindAndCountAll(r *Repository, queriers []rel.Querier) *FindAndCountAll

ExpectFindAndCountAll to be called with given field and queries.

func (*FindAndCountAll) ConnectionClosed

func (fa *FindAndCountAll) ConnectionClosed()

ConnectionClosed sets this error to be returned.

func (*FindAndCountAll) Error

func (fa *FindAndCountAll) Error(err error)

Error sets error to be returned.

func (*FindAndCountAll) Result

func (fa *FindAndCountAll) Result(records interface{}, count int)

Result sets the result of this query.

type Iterate

type Iterate iterator

Iterate asserts and simulate iterate function for test.

func ExpectIterate

func ExpectIterate(r *Repository, query rel.Query, options []rel.IteratorOption) *Iterate

ExpectIterate to be called.

func (*Iterate) ConnectionClosed

func (i *Iterate) ConnectionClosed()

ConnectionClosed sets this error to be returned.

func (*Iterate) Error

func (i *Iterate) Error(err error)

Error sets error to be returned.

func (*Iterate) Result

func (i *Iterate) Result(records interface{})

Result sets the result of this query.

type Mutate

type Mutate struct {
	*Expect
}

Mutate asserts and simulate insert or update function for test.

func ExpectInsert

func ExpectInsert(r *Repository, mutators []rel.Mutator) *Mutate

ExpectInsert to be called with given field and queries.

func ExpectInsertAll

func ExpectInsertAll(r *Repository) *Mutate

ExpectInsertAll to be called.

func ExpectUpdate

func ExpectUpdate(r *Repository, mutators []rel.Mutator) *Mutate

ExpectUpdate to be called with given field and queries.

func (*Mutate) For

func (m *Mutate) For(record interface{}) *Mutate

For match expect calls for given record.

func (*Mutate) ForType

func (m *Mutate) ForType(typ string) *Mutate

ForType match expect calls for given type. Type must include package name, example: `model.User`.

func (*Mutate) NotUnique

func (m *Mutate) NotUnique(key string)

NotUnique sets not unique error to be returned.

type MutateAny added in v0.17.0

type MutateAny struct {
	*Expect
}

MutateAny asserts and simulate mutate all function for test.

func ExpectDeleteAny added in v0.17.0

func ExpectDeleteAny(r *Repository, query rel.Query) *MutateAny

ExpectDeleteAny to be called.

func ExpectUpdateAny added in v0.17.0

func ExpectUpdateAny(r *Repository, query rel.Query, mutates []rel.Mutate) *MutateAny

ExpectUpdateAny to be called.

func (*MutateAny) ConnectionClosed added in v0.17.0

func (ma *MutateAny) ConnectionClosed()

ConnectionClosed sets this error to be returned.

func (*MutateAny) Error added in v0.17.0

func (ma *MutateAny) Error(err error)

Error sets error to be returned.

func (*MutateAny) Result added in v0.17.0

func (ma *MutateAny) Result(count int)

Result sets the returned number of deleted/updated counts.

func (*MutateAny) Unsafe added in v0.17.0

func (ma *MutateAny) Unsafe()

Unsafe allows for unsafe operation that doesn't contains where clause.

type Preload

type Preload struct {
	*Expect
}

Preload asserts and simulate preload function for test.

func ExpectPreload

func ExpectPreload(r *Repository, field string, queriers []rel.Querier) *Preload

ExpectPreload to be called with given field and queries.

func (*Preload) For

func (p *Preload) For(record interface{}) *Preload

For match expect calls for given record.

func (*Preload) ForType

func (p *Preload) ForType(typ string) *Preload

ForType match expect calls for given type. Type must include package name, example: `model.User`.

func (*Preload) Result

func (p *Preload) Result(records interface{})

Result sets the result of Preload query.

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 *testing.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.Cascade) 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 added in v0.17.0

func (r *Repository) DeleteAny(ctx context.Context, query rel.Query) (int, error)

DeleteAny provides a mock function with given fields: query

func (*Repository) Exec added in v0.14.0

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) *Aggregate

ExpectAggregate apply mocks and expectations for Aggregate

func (*Repository) ExpectCount

func (r *Repository) ExpectCount(collection string, queriers ...rel.Querier) *Aggregate

ExpectCount apply mocks and expectations for Count

func (*Repository) ExpectDelete

func (r *Repository) ExpectDelete(options ...rel.Cascade) *Delete

ExpectDelete apply mocks and expectations for Delete

func (*Repository) ExpectDeleteAll

func (r *Repository) ExpectDeleteAll() *Delete

ExpectDeleteAll apply mocks and expectations for DeleteAll

func (*Repository) ExpectDeleteAny added in v0.17.0

func (r *Repository) ExpectDeleteAny(query rel.Query) *MutateAny

ExpectDeleteAny apply mocks and expectations for DeleteAny

func (*Repository) ExpectExec added in v0.14.0

func (r *Repository) ExpectExec(statement string, args []interface{}) *Exec

ExpectExec for mocking Exec

func (*Repository) ExpectFind

func (r *Repository) ExpectFind(queriers ...rel.Querier) *Find

ExpectFind apply mocks and expectations for Find

func (*Repository) ExpectFindAll

func (r *Repository) ExpectFindAll(queriers ...rel.Querier) *FindAll

ExpectFindAll apply mocks and expectations for FindAll

func (*Repository) ExpectFindAndCountAll

func (r *Repository) ExpectFindAndCountAll(queriers ...rel.Querier) *FindAndCountAll

ExpectFindAndCountAll apply mocks and expectations for FindAndCountAll

func (*Repository) ExpectInsert

func (r *Repository) ExpectInsert(mutators ...rel.Mutator) *Mutate

ExpectInsert apply mocks and expectations for Insert

func (*Repository) ExpectInsertAll

func (r *Repository) ExpectInsertAll() *Mutate

ExpectInsertAll records.

func (*Repository) ExpectIterate

func (r *Repository) ExpectIterate(query rel.Query, options ...rel.IteratorOption) *Iterate

ExpectIterate apply mocks and expectations for Iterate

func (*Repository) ExpectPreload

func (r *Repository) ExpectPreload(field string, queriers ...rel.Querier) *Preload

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) *Mutate

ExpectUpdate apply mocks and expectations for Update

func (*Repository) ExpectUpdateAny added in v0.17.0

func (r *Repository) ExpectUpdateAny(query rel.Query, mutates ...rel.Mutate) *MutateAny

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{}) 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.Cascade)

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 added in v0.17.0

func (r *Repository) MustDeleteAny(ctx context.Context, query rel.Query) int

MustDeleteAny provides a mock function with given fields: query

func (*Repository) MustExec added in v0.14.0

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{})

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 added in v0.17.0

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 added in v0.17.0

func (r *Repository) UpdateAny(ctx context.Context, query rel.Query, mutates ...rel.Mutate) (int, error)

UpdateAny provides a mock function with given fields: query

Jump to

Keyboard shortcuts

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