mock

package
v0.0.0-...-f2d0a92 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 6

Documentation

Overview

Package mock contains mocked implementations of the interfaces defined in the anser package.

These implementations expose all internals and do not have external dependencies. Indeed they should have interface-definition-only dependencies on other anser packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Databases map[string]*Database
}

func NewClient

func NewClient() *Client

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

func (*Client) Database

func (c *Client) Database(name string) client.Database

func (*Client) Disconnect

func (c *Client) Disconnect(ctx context.Context) error

func (*Client) ListDatabaseNames

func (c *Client) ListDatabaseNames(ctx context.Context, query interface{}) ([]string, error)

type Collection

type Collection struct {
	CollName         string
	UpdateResult     client.UpdateResult
	SingleResult     *SingleResult
	InsertManyResult client.InsertManyResult
	InsertOneResult  client.InsertOneResult
	FindError        error
}

func (*Collection) Aggregate

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

func (*Collection) Find

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

func (*Collection) FindOne

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

func (*Collection) InsertMany

func (c *Collection) InsertMany(ctx context.Context, docs []interface{}) (*client.InsertManyResult, error)

func (*Collection) InsertOne

func (c *Collection) InsertOne(ctx context.Context, doc interface{}) (*client.InsertOneResult, error)

func (*Collection) Name

func (c *Collection) Name() string

func (*Collection) ReplaceOne

func (c *Collection) ReplaceOne(ctx context.Context, query, update interface{}, opts ...*options.ReplaceOptions) (*client.UpdateResult, error)

func (*Collection) UpdateMany

func (c *Collection) UpdateMany(ctx context.Context, query, update interface{}, opts ...*options.UpdateOptions) (*client.UpdateResult, error)

func (*Collection) UpdateOne

func (c *Collection) UpdateOne(ctx context.Context, query, update interface{}, opts ...*options.UpdateOptions) (*client.UpdateResult, error)

type Cursor

type Cursor struct {
	ShouldIter     bool
	CurrentValue   []byte
	Results        []interface{}
	AllError       error
	CloseError     error
	DecodeError    error
	ErrError       error
	CursorID       int64
	NextCallsCount int
	MaxNextCalls   int
}

func (*Cursor) All

func (c *Cursor) All(ctx context.Context, in interface{}) error

func (*Cursor) Close

func (c *Cursor) Close(ctx context.Context) error

func (*Cursor) Current

func (c *Cursor) Current() []byte

func (*Cursor) Decode

func (c *Cursor) Decode(in interface{}) error

func (*Cursor) Err

func (c *Cursor) Err() error

func (*Cursor) ID

func (c *Cursor) ID() int64

func (*Cursor) Next

func (c *Cursor) Next(ctx context.Context) bool

type Database

type Database struct {
	DBName      string
	Collections map[string]*Collection
}

func (*Database) Client

func (d *Database) Client() client.Client

func (*Database) Collection

func (d *Database) Collection(name string) client.Collection

func (*Database) Name

func (d *Database) Name() string

func (*Database) RunCommand

func (d *Database) RunCommand(ctx context.Context, cmd interface{}) client.SingleResult

func (*Database) RunCommandCursor

func (d *Database) RunCommandCursor(ctx context.Context, cmd interface{}) (client.Cursor, error)

type Iterator

type Iterator struct {
	Query       *Query
	Pipeline    *Pipeline
	ShouldIter  bool
	Error       error
	NumIterated int
	Results     []interface{}
}

func (*Iterator) Close

func (i *Iterator) Close() error

func (*Iterator) Err

func (i *Iterator) Err() error

func (*Iterator) Next

func (i *Iterator) Next(out interface{}) bool

type LegacyCollection

type LegacyCollection struct {
	Name         string
	InsertedDocs []interface{}
	UpdatedIds   []interface{}
	FailWrites   bool
	Queries      []*Query
	Pipelines    []*Pipeline
	NumDocs      int
	QueryError   error
	Mutex        sync.Mutex
}

func (*LegacyCollection) Bulk

func (c *LegacyCollection) Bulk() db.Bulk

func (*LegacyCollection) Count

func (c *LegacyCollection) Count() (int, error)

func (*LegacyCollection) DropCollection

func (c *LegacyCollection) DropCollection() error

func (*LegacyCollection) Find

func (c *LegacyCollection) Find(q interface{}) db.Query

func (*LegacyCollection) FindId

func (c *LegacyCollection) FindId(q interface{}) db.Query

func (*LegacyCollection) Insert

func (c *LegacyCollection) Insert(docs ...interface{}) error

func (*LegacyCollection) Pipe

func (c *LegacyCollection) Pipe(p interface{}) db.Aggregation

func (*LegacyCollection) Remove

func (c *LegacyCollection) Remove(q interface{}) error

func (*LegacyCollection) RemoveAll

func (c *LegacyCollection) RemoveAll(q interface{}) (*db.ChangeInfo, error)

func (*LegacyCollection) RemoveId

func (c *LegacyCollection) RemoveId(id interface{}) error

func (*LegacyCollection) Update

func (c *LegacyCollection) Update(q, u interface{}) error

func (*LegacyCollection) UpdateAll

func (c *LegacyCollection) UpdateAll(q, u interface{}) (*db.ChangeInfo, error)

func (*LegacyCollection) UpdateId

func (c *LegacyCollection) UpdateId(id, u interface{}) error

func (*LegacyCollection) Upsert

func (c *LegacyCollection) Upsert(q, u interface{}) (*db.ChangeInfo, error)

func (*LegacyCollection) UpsertId

func (c *LegacyCollection) UpsertId(id, u interface{}) (*db.ChangeInfo, error)

type LegacyDatabase

type LegacyDatabase struct {
	Collections map[string]*LegacyCollection
	DBName      string
	Mutex       sync.Mutex
}

func (*LegacyDatabase) C

func (*LegacyDatabase) CreateCollection

func (d *LegacyDatabase) CreateCollection(coll string) (db.Collection, error)

func (*LegacyDatabase) DropDatabase

func (d *LegacyDatabase) DropDatabase() error

func (*LegacyDatabase) Name

func (d *LegacyDatabase) Name() string

type Pipeline

type Pipeline struct {
	Pipe  interface{}
	Error error
}

func (*Pipeline) All

func (p *Pipeline) All(r interface{}) error

func (*Pipeline) Hint

func (p *Pipeline) Hint(hint interface{}) db.Aggregation

func (*Pipeline) Iter

func (p *Pipeline) Iter() db.Iterator

func (*Pipeline) MaxTime

func (p *Pipeline) MaxTime(d time.Duration) db.Aggregation

func (*Pipeline) One

func (p *Pipeline) One(r interface{}) error

type Query

type Query struct {
	Query           interface{}
	Project         interface{}
	SortKeys        []string
	NumLimit        int
	NumSkip         int
	IndexHint       interface{}
	MaxQTime        time.Duration
	Error           error
	CountNum        int
	ApplyChangeSpec db.Change
	ApplyChangeInfo *db.ChangeInfo
}

func (*Query) All

func (q *Query) All(r interface{}) error

func (*Query) Apply

func (q *Query) Apply(ch db.Change, r interface{}) (*db.ChangeInfo, error)

func (*Query) Count

func (q *Query) Count() (int, error)

func (*Query) Hint

func (q *Query) Hint(h interface{}) db.Query

func (*Query) Iter

func (q *Query) Iter() db.Iterator

func (*Query) Limit

func (q *Query) Limit(n int) db.Query

func (*Query) MaxTime

func (q *Query) MaxTime(d time.Duration) db.Query

func (*Query) One

func (q *Query) One(r interface{}) error

func (*Query) Select

func (q *Query) Select(p interface{}) db.Query

func (*Query) Skip

func (q *Query) Skip(n int) db.Query

func (*Query) Sort

func (q *Query) Sort(keys ...string) db.Query

type Session

type Session struct {
	DBs           map[string]*LegacyDatabase
	URI           string
	Closed        bool
	SocketTimeout time.Duration
	Mutex         sync.Mutex
}

func NewSession

func NewSession() *Session

func (*Session) Clone

func (s *Session) Clone() db.Session

func (*Session) Close

func (s *Session) Close()

func (*Session) Copy

func (s *Session) Copy() db.Session

func (*Session) DB

func (s *Session) DB(n string) db.Database

func (*Session) Error

func (s *Session) Error() error

func (*Session) SetSocketTimeout

func (s *Session) SetSocketTimeout(d time.Duration)

type SingleResult

type SingleResult struct {
	DecodeError      error
	DecodeBytesError error
	DecodeBytesValue []byte
	ErrorValue       error
}

func NewSingleResult

func NewSingleResult() *SingleResult

func (*SingleResult) Decode

func (sr *SingleResult) Decode(in interface{}) error

func (*SingleResult) Err

func (sr *SingleResult) Err() error

func (*SingleResult) Raw

func (sr *SingleResult) Raw() ([]byte, error)

Jump to

Keyboard shortcuts

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