mock

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientMock

type ClientMock struct {
	// CheckerFunc mocks the Checker method.
	CheckerFunc func(contextMoqParam context.Context, checkState *healthcheck.CheckState) error

	// CloseFunc mocks the Close method.
	CloseFunc func(contextMoqParam context.Context) error

	// CollectionFunc mocks the Collection method.
	CollectionFunc func(s string) *mongodriver.Collection

	// ConnectionFunc mocks the Connection method.
	ConnectionFunc func() *mongodriver.MongoConnection

	// URIFunc mocks the URI method.
	URIFunc func() string
	// contains filtered or unexported fields
}

ClientMock is a mock implementation of mongo.Client.

func TestSomethingThatUsesClient(t *testing.T) {

	// make and configure a mocked mongo.Client
	mockedClient := &ClientMock{
		CheckerFunc: func(contextMoqParam context.Context, checkState *healthcheck.CheckState) error {
			panic("mock out the Checker method")
		},
		CloseFunc: func(contextMoqParam context.Context) error {
			panic("mock out the Close method")
		},
		CollectionFunc: func(s string) *mongodriver.Collection {
			panic("mock out the Collection method")
		},
		ConnectionFunc: func() *mongodriver.MongoConnection {
			panic("mock out the Connection method")
		},
		URIFunc: func() string {
			panic("mock out the URI method")
		},
	}

	// use mockedClient in code that requires mongo.Client
	// and then make assertions.

}

func (*ClientMock) Checker

func (mock *ClientMock) Checker(contextMoqParam context.Context, checkState *healthcheck.CheckState) error

Checker calls CheckerFunc.

func (*ClientMock) CheckerCalls

func (mock *ClientMock) CheckerCalls() []struct {
	ContextMoqParam context.Context
	CheckState      *healthcheck.CheckState
}

CheckerCalls gets all the calls that were made to Checker. Check the length with:

len(mockedClient.CheckerCalls())

func (*ClientMock) Close

func (mock *ClientMock) Close(contextMoqParam context.Context) error

Close calls CloseFunc.

func (*ClientMock) CloseCalls

func (mock *ClientMock) CloseCalls() []struct {
	ContextMoqParam context.Context
}

CloseCalls gets all the calls that were made to Close. Check the length with:

len(mockedClient.CloseCalls())

func (*ClientMock) Collection

func (mock *ClientMock) Collection(s string) *mongodriver.Collection

Collection calls CollectionFunc.

func (*ClientMock) CollectionCalls

func (mock *ClientMock) CollectionCalls() []struct {
	S string
}

CollectionCalls gets all the calls that were made to Collection. Check the length with:

len(mockedClient.CollectionCalls())

func (*ClientMock) Connection

func (mock *ClientMock) Connection() *mongodriver.MongoConnection

Connection calls ConnectionFunc.

func (*ClientMock) ConnectionCalls

func (mock *ClientMock) ConnectionCalls() []struct {
}

ConnectionCalls gets all the calls that were made to Connection. Check the length with:

len(mockedClient.ConnectionCalls())

func (*ClientMock) URI

func (mock *ClientMock) URI() string

URI calls URIFunc.

func (*ClientMock) URICalls

func (mock *ClientMock) URICalls() []struct {
}

URICalls gets all the calls that were made to URI. Check the length with:

len(mockedClient.URICalls())

type MongoCollectionMock

type MongoCollectionMock struct {
	// AggregateFunc mocks the Aggregate method.
	AggregateFunc func(ctx context.Context, pipeline interface{}, results interface{}) error

	// CountFunc mocks the Count method.
	CountFunc func(ctx context.Context, filter interface{}, opts ...mongodriver.FindOption) (int, error)

	// DeleteFunc mocks the Delete method.
	DeleteFunc func(ctx context.Context, selector interface{}) (*mongodriver.CollectionDeleteResult, error)

	// DeleteByIdFunc mocks the DeleteById method.
	DeleteByIdFunc func(ctx context.Context, id interface{}) (*mongodriver.CollectionDeleteResult, error)

	// DeleteManyFunc mocks the DeleteMany method.
	DeleteManyFunc func(ctx context.Context, selector interface{}) (*mongodriver.CollectionDeleteResult, error)

	// DistinctFunc mocks the Distinct method.
	DistinctFunc func(ctx context.Context, fieldName string, filter interface{}) ([]interface{}, error)

	// FindFunc mocks the Find method.
	FindFunc func(ctx context.Context, filter interface{}, results interface{}, opts ...mongodriver.FindOption) (int, error)

	// FindCursorFunc mocks the FindCursor method.
	FindCursorFunc func(ctx context.Context, filter interface{}, opts ...mongodriver.FindOption) (mongodriver.Cursor, error)

	// FindOneFunc mocks the FindOne method.
	FindOneFunc func(ctx context.Context, filter interface{}, result interface{}, opts ...mongodriver.FindOption) error

	// InsertFunc mocks the Insert method.
	InsertFunc func(ctx context.Context, document interface{}) (*mongodriver.CollectionInsertResult, error)

	// InsertManyFunc mocks the InsertMany method.
	InsertManyFunc func(ctx context.Context, documents []interface{}) (*mongodriver.CollectionInsertManyResult, error)

	// MustFunc mocks the Must method.
	MustFunc func() *mongodriver.Must

	// NewLockClientFunc mocks the NewLockClient method.
	NewLockClientFunc func() *lock.Client

	// UpdateFunc mocks the Update method.
	UpdateFunc func(ctx context.Context, selector interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error)

	// UpdateByIdFunc mocks the UpdateById method.
	UpdateByIdFunc func(ctx context.Context, id interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error)

	// UpdateManyFunc mocks the UpdateMany method.
	UpdateManyFunc func(ctx context.Context, selector interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error)

	// UpdateOneFunc mocks the UpdateOne method.
	UpdateOneFunc func(ctx context.Context, selector interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error)

	// UpsertFunc mocks the Upsert method.
	UpsertFunc func(ctx context.Context, selector interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error)

	// UpsertByIdFunc mocks the UpsertById method.
	UpsertByIdFunc func(ctx context.Context, id interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error)
	// contains filtered or unexported fields
}

MongoCollectionMock is a mock implementation of mongo.MongoCollection.

func TestSomethingThatUsesMongoCollection(t *testing.T) {

	// make and configure a mocked mongo.MongoCollection
	mockedMongoCollection := &MongoCollectionMock{
		AggregateFunc: func(ctx context.Context, pipeline interface{}, results interface{}) error {
			panic("mock out the Aggregate method")
		},
		CountFunc: func(ctx context.Context, filter interface{}, opts ...mongodriver.FindOption) (int, error) {
			panic("mock out the Count method")
		},
		DeleteFunc: func(ctx context.Context, selector interface{}) (*mongodriver.CollectionDeleteResult, error) {
			panic("mock out the Delete method")
		},
		DeleteByIdFunc: func(ctx context.Context, id interface{}) (*mongodriver.CollectionDeleteResult, error) {
			panic("mock out the DeleteById method")
		},
		DeleteManyFunc: func(ctx context.Context, selector interface{}) (*mongodriver.CollectionDeleteResult, error) {
			panic("mock out the DeleteMany method")
		},
		DistinctFunc: func(ctx context.Context, fieldName string, filter interface{}) ([]interface{}, error) {
			panic("mock out the Distinct method")
		},
		FindFunc: func(ctx context.Context, filter interface{}, results interface{}, opts ...mongodriver.FindOption) (int, error) {
			panic("mock out the Find method")
		},
		FindCursorFunc: func(ctx context.Context, filter interface{}, opts ...mongodriver.FindOption) (mongodriver.Cursor, error) {
			panic("mock out the FindCursor method")
		},
		FindOneFunc: func(ctx context.Context, filter interface{}, result interface{}, opts ...mongodriver.FindOption) error {
			panic("mock out the FindOne method")
		},
		InsertFunc: func(ctx context.Context, document interface{}) (*mongodriver.CollectionInsertResult, error) {
			panic("mock out the Insert method")
		},
		InsertManyFunc: func(ctx context.Context, documents []interface{}) (*mongodriver.CollectionInsertManyResult, error) {
			panic("mock out the InsertMany method")
		},
		MustFunc: func() *mongodriver.Must {
			panic("mock out the Must method")
		},
		NewLockClientFunc: func() *lock.Client {
			panic("mock out the NewLockClient method")
		},
		UpdateFunc: func(ctx context.Context, selector interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error) {
			panic("mock out the Update method")
		},
		UpdateByIdFunc: func(ctx context.Context, id interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error) {
			panic("mock out the UpdateById method")
		},
		UpdateManyFunc: func(ctx context.Context, selector interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error) {
			panic("mock out the UpdateMany method")
		},
		UpdateOneFunc: func(ctx context.Context, selector interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error) {
			panic("mock out the UpdateOne method")
		},
		UpsertFunc: func(ctx context.Context, selector interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error) {
			panic("mock out the Upsert method")
		},
		UpsertByIdFunc: func(ctx context.Context, id interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error) {
			panic("mock out the UpsertById method")
		},
	}

	// use mockedMongoCollection in code that requires mongo.MongoCollection
	// and then make assertions.

}

func (*MongoCollectionMock) Aggregate

func (mock *MongoCollectionMock) Aggregate(ctx context.Context, pipeline interface{}, results interface{}) error

Aggregate calls AggregateFunc.

func (*MongoCollectionMock) AggregateCalls

func (mock *MongoCollectionMock) AggregateCalls() []struct {
	Ctx      context.Context
	Pipeline interface{}
	Results  interface{}
}

AggregateCalls gets all the calls that were made to Aggregate. Check the length with:

len(mockedMongoCollection.AggregateCalls())

func (*MongoCollectionMock) Count

func (mock *MongoCollectionMock) Count(ctx context.Context, filter interface{}, opts ...mongodriver.FindOption) (int, error)

Count calls CountFunc.

func (*MongoCollectionMock) CountCalls

func (mock *MongoCollectionMock) CountCalls() []struct {
	Ctx    context.Context
	Filter interface{}
	Opts   []mongodriver.FindOption
}

CountCalls gets all the calls that were made to Count. Check the length with:

len(mockedMongoCollection.CountCalls())

func (*MongoCollectionMock) Delete

func (mock *MongoCollectionMock) Delete(ctx context.Context, selector interface{}) (*mongodriver.CollectionDeleteResult, error)

Delete calls DeleteFunc.

func (*MongoCollectionMock) DeleteById

func (mock *MongoCollectionMock) DeleteById(ctx context.Context, id interface{}) (*mongodriver.CollectionDeleteResult, error)

DeleteById calls DeleteByIdFunc.

func (*MongoCollectionMock) DeleteByIdCalls

func (mock *MongoCollectionMock) DeleteByIdCalls() []struct {
	Ctx context.Context
	ID  interface{}
}

DeleteByIdCalls gets all the calls that were made to DeleteById. Check the length with:

len(mockedMongoCollection.DeleteByIdCalls())

func (*MongoCollectionMock) DeleteCalls

func (mock *MongoCollectionMock) DeleteCalls() []struct {
	Ctx      context.Context
	Selector interface{}
}

DeleteCalls gets all the calls that were made to Delete. Check the length with:

len(mockedMongoCollection.DeleteCalls())

func (*MongoCollectionMock) DeleteMany

func (mock *MongoCollectionMock) DeleteMany(ctx context.Context, selector interface{}) (*mongodriver.CollectionDeleteResult, error)

DeleteMany calls DeleteManyFunc.

func (*MongoCollectionMock) DeleteManyCalls

func (mock *MongoCollectionMock) DeleteManyCalls() []struct {
	Ctx      context.Context
	Selector interface{}
}

DeleteManyCalls gets all the calls that were made to DeleteMany. Check the length with:

len(mockedMongoCollection.DeleteManyCalls())

func (*MongoCollectionMock) Distinct

func (mock *MongoCollectionMock) Distinct(ctx context.Context, fieldName string, filter interface{}) ([]interface{}, error)

Distinct calls DistinctFunc.

func (*MongoCollectionMock) DistinctCalls

func (mock *MongoCollectionMock) DistinctCalls() []struct {
	Ctx       context.Context
	FieldName string
	Filter    interface{}
}

DistinctCalls gets all the calls that were made to Distinct. Check the length with:

len(mockedMongoCollection.DistinctCalls())

func (*MongoCollectionMock) Find

func (mock *MongoCollectionMock) Find(ctx context.Context, filter interface{}, results interface{}, opts ...mongodriver.FindOption) (int, error)

Find calls FindFunc.

func (*MongoCollectionMock) FindCalls

func (mock *MongoCollectionMock) FindCalls() []struct {
	Ctx     context.Context
	Filter  interface{}
	Results interface{}
	Opts    []mongodriver.FindOption
}

FindCalls gets all the calls that were made to Find. Check the length with:

len(mockedMongoCollection.FindCalls())

func (*MongoCollectionMock) FindCursor added in v1.2.0

func (mock *MongoCollectionMock) FindCursor(ctx context.Context, filter interface{}, opts ...mongodriver.FindOption) (mongodriver.Cursor, error)

FindCursor calls FindCursorFunc.

func (*MongoCollectionMock) FindCursorCalls added in v1.2.0

func (mock *MongoCollectionMock) FindCursorCalls() []struct {
	Ctx    context.Context
	Filter interface{}
	Opts   []mongodriver.FindOption
}

FindCursorCalls gets all the calls that were made to FindCursor. Check the length with:

len(mockedMongoCollection.FindCursorCalls())

func (*MongoCollectionMock) FindOne

func (mock *MongoCollectionMock) FindOne(ctx context.Context, filter interface{}, result interface{}, opts ...mongodriver.FindOption) error

FindOne calls FindOneFunc.

func (*MongoCollectionMock) FindOneCalls

func (mock *MongoCollectionMock) FindOneCalls() []struct {
	Ctx    context.Context
	Filter interface{}
	Result interface{}
	Opts   []mongodriver.FindOption
}

FindOneCalls gets all the calls that were made to FindOne. Check the length with:

len(mockedMongoCollection.FindOneCalls())

func (*MongoCollectionMock) Insert

func (mock *MongoCollectionMock) Insert(ctx context.Context, document interface{}) (*mongodriver.CollectionInsertResult, error)

Insert calls InsertFunc.

func (*MongoCollectionMock) InsertCalls

func (mock *MongoCollectionMock) InsertCalls() []struct {
	Ctx      context.Context
	Document interface{}
}

InsertCalls gets all the calls that were made to Insert. Check the length with:

len(mockedMongoCollection.InsertCalls())

func (*MongoCollectionMock) InsertMany

func (mock *MongoCollectionMock) InsertMany(ctx context.Context, documents []interface{}) (*mongodriver.CollectionInsertManyResult, error)

InsertMany calls InsertManyFunc.

func (*MongoCollectionMock) InsertManyCalls

func (mock *MongoCollectionMock) InsertManyCalls() []struct {
	Ctx       context.Context
	Documents []interface{}
}

InsertManyCalls gets all the calls that were made to InsertMany. Check the length with:

len(mockedMongoCollection.InsertManyCalls())

func (*MongoCollectionMock) Must

func (mock *MongoCollectionMock) Must() *mongodriver.Must

Must calls MustFunc.

func (*MongoCollectionMock) MustCalls

func (mock *MongoCollectionMock) MustCalls() []struct {
}

MustCalls gets all the calls that were made to Must. Check the length with:

len(mockedMongoCollection.MustCalls())

func (*MongoCollectionMock) NewLockClient

func (mock *MongoCollectionMock) NewLockClient() *lock.Client

NewLockClient calls NewLockClientFunc.

func (*MongoCollectionMock) NewLockClientCalls

func (mock *MongoCollectionMock) NewLockClientCalls() []struct {
}

NewLockClientCalls gets all the calls that were made to NewLockClient. Check the length with:

len(mockedMongoCollection.NewLockClientCalls())

func (*MongoCollectionMock) Update

func (mock *MongoCollectionMock) Update(ctx context.Context, selector interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error)

Update calls UpdateFunc.

func (*MongoCollectionMock) UpdateById

func (mock *MongoCollectionMock) UpdateById(ctx context.Context, id interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error)

UpdateById calls UpdateByIdFunc.

func (*MongoCollectionMock) UpdateByIdCalls

func (mock *MongoCollectionMock) UpdateByIdCalls() []struct {
	Ctx    context.Context
	ID     interface{}
	Update interface{}
}

UpdateByIdCalls gets all the calls that were made to UpdateById. Check the length with:

len(mockedMongoCollection.UpdateByIdCalls())

func (*MongoCollectionMock) UpdateCalls

func (mock *MongoCollectionMock) UpdateCalls() []struct {
	Ctx      context.Context
	Selector interface{}
	Update   interface{}
}

UpdateCalls gets all the calls that were made to Update. Check the length with:

len(mockedMongoCollection.UpdateCalls())

func (*MongoCollectionMock) UpdateMany

func (mock *MongoCollectionMock) UpdateMany(ctx context.Context, selector interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error)

UpdateMany calls UpdateManyFunc.

func (*MongoCollectionMock) UpdateManyCalls

func (mock *MongoCollectionMock) UpdateManyCalls() []struct {
	Ctx      context.Context
	Selector interface{}
	Update   interface{}
}

UpdateManyCalls gets all the calls that were made to UpdateMany. Check the length with:

len(mockedMongoCollection.UpdateManyCalls())

func (*MongoCollectionMock) UpdateOne added in v1.24.0

func (mock *MongoCollectionMock) UpdateOne(ctx context.Context, selector interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error)

UpdateOne calls UpdateOneFunc.

func (*MongoCollectionMock) UpdateOneCalls added in v1.24.0

func (mock *MongoCollectionMock) UpdateOneCalls() []struct {
	Ctx      context.Context
	Selector interface{}
	Update   interface{}
}

UpdateOneCalls gets all the calls that were made to UpdateOne. Check the length with:

len(mockedMongoCollection.UpdateOneCalls())

func (*MongoCollectionMock) Upsert

func (mock *MongoCollectionMock) Upsert(ctx context.Context, selector interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error)

Upsert calls UpsertFunc.

func (*MongoCollectionMock) UpsertById

func (mock *MongoCollectionMock) UpsertById(ctx context.Context, id interface{}, update interface{}) (*mongodriver.CollectionUpdateResult, error)

UpsertById calls UpsertByIdFunc.

func (*MongoCollectionMock) UpsertByIdCalls

func (mock *MongoCollectionMock) UpsertByIdCalls() []struct {
	Ctx    context.Context
	ID     interface{}
	Update interface{}
}

UpsertByIdCalls gets all the calls that were made to UpsertById. Check the length with:

len(mockedMongoCollection.UpsertByIdCalls())

func (*MongoCollectionMock) UpsertCalls

func (mock *MongoCollectionMock) UpsertCalls() []struct {
	Ctx      context.Context
	Selector interface{}
	Update   interface{}
}

UpsertCalls gets all the calls that were made to Upsert. Check the length with:

len(mockedMongoCollection.UpsertCalls())

type MongoCursorMock added in v1.2.0

type MongoCursorMock struct {
	// CloseFunc mocks the Close method.
	CloseFunc func(ctx context.Context) error

	// DecodeFunc mocks the Decode method.
	DecodeFunc func(val interface{}) error

	// ErrFunc mocks the Err method.
	ErrFunc func() error

	// NextFunc mocks the Next method.
	NextFunc func(ctx context.Context) bool
	// contains filtered or unexported fields
}

MongoCursorMock is a mock implementation of mongo.MongoCursor.

func TestSomethingThatUsesMongoCursor(t *testing.T) {

	// make and configure a mocked mongo.MongoCursor
	mockedMongoCursor := &MongoCursorMock{
		CloseFunc: func(ctx context.Context) error {
			panic("mock out the Close method")
		},
		DecodeFunc: func(val interface{}) error {
			panic("mock out the Decode method")
		},
		ErrFunc: func() error {
			panic("mock out the Err method")
		},
		NextFunc: func(ctx context.Context) bool {
			panic("mock out the Next method")
		},
	}

	// use mockedMongoCursor in code that requires mongo.MongoCursor
	// and then make assertions.

}

func (*MongoCursorMock) Close added in v1.2.0

func (mock *MongoCursorMock) Close(ctx context.Context) error

Close calls CloseFunc.

func (*MongoCursorMock) CloseCalls added in v1.2.0

func (mock *MongoCursorMock) CloseCalls() []struct {
	Ctx context.Context
}

CloseCalls gets all the calls that were made to Close. Check the length with:

len(mockedMongoCursor.CloseCalls())

func (*MongoCursorMock) Decode added in v1.2.0

func (mock *MongoCursorMock) Decode(val interface{}) error

Decode calls DecodeFunc.

func (*MongoCursorMock) DecodeCalls added in v1.2.0

func (mock *MongoCursorMock) DecodeCalls() []struct {
	Val interface{}
}

DecodeCalls gets all the calls that were made to Decode. Check the length with:

len(mockedMongoCursor.DecodeCalls())

func (*MongoCursorMock) Err added in v1.2.0

func (mock *MongoCursorMock) Err() error

Err calls ErrFunc.

func (*MongoCursorMock) ErrCalls added in v1.2.0

func (mock *MongoCursorMock) ErrCalls() []struct {
}

ErrCalls gets all the calls that were made to Err. Check the length with:

len(mockedMongoCursor.ErrCalls())

func (*MongoCursorMock) Next added in v1.2.0

func (mock *MongoCursorMock) Next(ctx context.Context) bool

Next calls NextFunc.

func (*MongoCursorMock) NextCalls added in v1.2.0

func (mock *MongoCursorMock) NextCalls() []struct {
	Ctx context.Context
}

NextCalls gets all the calls that were made to Next. Check the length with:

len(mockedMongoCursor.NextCalls())

Jump to

Keyboard shortcuts

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