kmongo

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

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

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

func NewCollection

func NewCollection(cl *mongo.Collection) *Collection

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

  • In keploy.MODE_RECORD mode, stores the encoded output(generated by mocked methods of mongo.Collection) into keploy's Context Deps array.
  • In keploy.MODE_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.Collection which contains mongo.Collection. Nil is returned when mongo.Collection is nil.

func (*Collection) Aggregate

func (c *Collection) Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (*Cursor, error)

Aggregate method mocks Collection.Aggregate of mongo inorder to call it only in keploy.MODE_RECORD or "off" mode.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection.Aggregate for more info about Aggregate.

func (*Collection) CountDocuments

func (c *Collection) CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error)

CountDocuments method mocks Collection.CountDocuments of mongo inorder to call it only in keploy.MODE_RECORD or "off" mode.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection.CountDocuments for more info about CountDocuments.

func (*Collection) DeleteMany

func (c *Collection) 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 keploy.MODE_RECORD 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 (*Collection) DeleteOne

func (c *Collection) 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 (*Collection) Distinct

func (c *Collection) Distinct(ctx context.Context, fieldName string, filter interface{}, opts ...*options.DistinctOptions) ([]interface{}, error)

Distinct method mocks Collection.Distinct of mongo inorder to call it only in keploy.MODE_RECORD or "off" mode.

See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection.Distinct for more info about Distinct.

func (*Collection) Find

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

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

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

func (*Collection) FindOne

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

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

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

func (*Collection) InsertMany

func (c *Collection) 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 (*Collection) InsertOne

func (c *Collection) 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.NewCollection.

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

func (*Collection) UpdateMany

func (c *Collection) 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 (*Collection) UpdateOne

func (c *Collection) 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 Cursor

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

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

func (*Cursor) All

func (cr *Cursor) 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 (*Cursor) Close

func (cr *Cursor) 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 (*Cursor) Decode

func (cr *Cursor) 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 (*Cursor) Err

func (cr *Cursor) 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 (*Cursor) Next

func (cr *Cursor) 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 (*Cursor) TryNext

func (cr *Cursor) 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 SingleResult

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

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

  • In keploy.MODE_RECORD mode, stores the encoded output(generated by mocked methods of mongo.SingleResult) into keploy's Context Deps array.
  • In keploy.MODE_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 (*SingleResult) Decode

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

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

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

func (*SingleResult) Err

func (msr *SingleResult) Err() error

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

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