kmongo

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoCollection

type MongoCollection struct {
	mongo.Collection
	// contains filtered or unexported fields
}

MongoCollection: In order to mock mongo operations, mongo collection is embedded into MongoCollection.

func NewMongoCollection

func NewMongoCollection(cl *mongo.Collection) *MongoCollection

NewMongoCollection creates and returns an instance of MongoCollection that contains actual pointer to mongo's collection. This is done in order to mock mongo CRUD operations, so that:

  • In "capture" mode, stores the encoded output(generated by mocked methods of mongo.Collection) into keploy's Context Deps array.
  • In "test" mode, decodes its stored encoded output which are present in the keploy's Context Deps array without calling mocked methods of mongo.Collection.
  • In "off" mode, returns the output generated after calling mocked method of mongo.Collection.

cl parameter is pointer to mongo's collection instance created by (*mongo.Database).Collection method. It should not be nil, else warning will logged and nil is returned.

Returns pointer to integrations.MongoCollection which contains mongo.Collection. Nil is returned when mongo.Collection is nil.

func (*MongoCollection) DeleteMany

func (c *MongoCollection) DeleteMany(ctx context.Context, filter interface{},
	opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

DeleteMany method mocks Collection.DeleteMany of mongo inorder to call it only in "capture" or "off" mode.

See https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.8.0/mongo#Collection.DeleteMany for information about Collection.DeleteMany.

func (*MongoCollection) DeleteOne

func (c *MongoCollection) DeleteOne(ctx context.Context, filter interface{},
	opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

DeleteOne method mocks Collection.DeleteOne of mongo.

See https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.8.0/mongo#Collection.DeleteOne for information about Collection.DeleteOne.

func (*MongoCollection) Find

func (c *MongoCollection) Find(ctx context.Context, filter interface{},
	opts ...*options.FindOptions) (*MongoCursor, error)

Find creates and returns the instance of pointer to MongoCursor which have overridden methods of mongo.Cursor. Actual Collection.Find is called only in "capture" or "off" mode.

For information about Collection.Find, See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection.Find.

func (*MongoCollection) FindOne

func (c *MongoCollection) FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *MongoSingleResult

FindOne method creates and returns pointer of MongoSingleResult which containes mongo.SingleResult in order to mock its method. It mocks Collection.FindOne method explained above in integrations.NewMongoCollections.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection.FindOne for information about Collection.FindOne.

func (*MongoCollection) InsertMany

func (c *MongoCollection) InsertMany(ctx context.Context, documents []interface{},
	opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)

InsertMany method mocks Collection.InsertMany of mongo.

For information about Collection.InsertMany, visit https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.8.0/mongo#Collection.InsertMany.

func (*MongoCollection) InsertOne

func (c *MongoCollection) InsertOne(ctx context.Context, document interface{},
	opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)

InsertOne method mocks Collection.InsertOne of mongo.Collection. Actual method isn't called in test mode only as stated in integrations.NewMongoCollection.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection.InsertOne for information about Collection.InsertOne.

func (*MongoCollection) UpdateMany

func (c *MongoCollection) UpdateMany(ctx context.Context, filter interface{}, update interface{},
	opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateMany method mocks Collection.UpdateMany of mongo.

For information about Collection.UpdateMany, go to https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.8.0/mongo#Collection.UpdateMany.

func (*MongoCollection) UpdateOne

func (c *MongoCollection) UpdateOne(ctx context.Context, filter interface{}, update interface{},
	opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateOne method mocks Collection.UpdateOne of mongo.

For information about Collection.UpdateOne, refer to https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.8.0/mongo#Collection.UpdateOne.

type MongoCursor

type MongoCursor struct {
	mongo.Cursor
	// contains filtered or unexported fields
}

MongoCursor contains emedded mongo.Cursor in order to override its methods.

func (*MongoCursor) All

func (cr *MongoCursor) All(ctx context.Context, results interface{}) error

All mocks mongo's Cursor.All in order to store and replay its output according SDK mode.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Cursor.All for information about Cursor.All.

func (*MongoCursor) Close

func (cr *MongoCursor) Close(ctx context.Context) error

Close mocks mongo's Cursor.Close in order to store and replay its output according SDK mode.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Cursor.Close for information about Cursor.Close.

func (*MongoCursor) Decode

func (cr *MongoCursor) Decode(v interface{}) error

Decode mocks mongo's Cursor.Decode in order to store and replay its output according SDK mode.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Cursor.Decode for information about Cursor.Decode.

func (*MongoCursor) Err

func (cr *MongoCursor) Err() error

Err mocks mongo's Cursor.Err in order to store and replay its output according SDK mode.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Cursor.Err for information about Cursor.Err.

func (*MongoCursor) Next

func (cr *MongoCursor) Next(ctx context.Context) bool

Next mocks mongo's Cursor.Next in order to store and replay its output according SDK mode.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Cursor.Next for information about Cursor.Next.

func (*MongoCursor) TryNext

func (cr *MongoCursor) TryNext(ctx context.Context) bool

TryNext mocks mongo's Cursor.TryNext in order to store and replay its output according SDK mode.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Cursor.TryNext for information about Cursor.TryNext.

type MongoSingleResult

type MongoSingleResult struct {
	mongo.SingleResult
	// contains filtered or unexported fields
}

MongoSingleResult countains instance of mongo.SingleResult to mock its methods so that:

  • In "capture" mode, stores the encoded output(generated by mocked methods of mongo.SingleResult) into keploy's Context Deps array.
  • In "test" mode, decodes its stored encoded output which are present in the keploy's Context Deps array without calling mocked methods of mongo.SingleResult.
  • In "off" mode, returns the output generated after calling mocked method of mongo.SingleResult.

func (*MongoSingleResult) Decode

func (msr *MongoSingleResult) Decode(v interface{}) error

Decode mocks mongo's SingleResult.Decode which will called in "capture" or "off" mode as stated above in MongoSingleResult.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#SingleResult.Decode for more information about SingleResult.Decode.

func (*MongoSingleResult) Err

func (msr *MongoSingleResult) Err() error

Err mocks mongo's SingleResult Err() which will called in "capture" or "off" mode as stated above in MongoSingleResult.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#SingleResult.Err for more information about SingleResult.Err.

Jump to

Keyboard shortcuts

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