I'm writing some code in Go. I want to unit test my code - a wrapper created for MongoDB Go Driver:
The problem is I don't know how to mock some functions of MongoDB internals (like collection's methods).
For example there is one function from collection.go:
func (coll *Collection) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (*Cursor, error) {
//...
}
I've created interface for Collection and mocks, to cover this functionality (something like that):
type IDBProviderCollection interface {
//...
Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (*Cursor, error)
}
The problem is that this function returns struct, which is too complex for doing some workarounds. All i want is just to mock this function - to return cursor to fake data, and after cursor.Next() function in Cursor struct, there will be new fake data. Now it panics beacuse internals of mongo.Cursor are not satisfied, which is logical, beacuse I'm faking MongoDB database.