mock

package
v0.0.0-...-2a589a5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: Apache-2.0 Imports: 18 Imported by: 4

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 DependencyManager

type DependencyManager struct {
	Name       string
	Query      map[string]interface{}
	StateValue dependency.State
	T          dependency.TypeInfo
	*dependency.JobEdges
}

func (*DependencyManager) State

func (d *DependencyManager) State() dependency.State

func (*DependencyManager) Type

type DependencyNetwork

type DependencyNetwork struct {
	Graph         map[string][]string
	Groups        map[string][]string
	ValidateError error
}

DependencyNetwork provides a mock implementation of the anser.DependencyNetworker interface. This implementation, unlike the default one, does no deduplicate the dependency.

func NewDependencyNetwork

func NewDependencyNetwork() *DependencyNetwork

func (*DependencyNetwork) Add

func (n *DependencyNetwork) Add(name string, deps []string)

func (*DependencyNetwork) AddGroup

func (n *DependencyNetwork) AddGroup(name string, group []string)

func (*DependencyNetwork) All

func (n *DependencyNetwork) All() []string

func (*DependencyNetwork) GetGroup

func (n *DependencyNetwork) GetGroup(name string) []string

func (*DependencyNetwork) MarshalJSON

func (n *DependencyNetwork) MarshalJSON() ([]byte, error)

func (*DependencyNetwork) Network

func (n *DependencyNetwork) Network() map[string][]string

func (*DependencyNetwork) Resolve

func (n *DependencyNetwork) Resolve(name string) []string

func (*DependencyNetwork) String

func (n *DependencyNetwork) String() string

func (*DependencyNetwork) Validate

func (n *DependencyNetwork) Validate() error

type Environment

type Environment struct {
	IsSetup         bool
	ReturnNilClient bool
	SetupError      error
	SessionError    error
	ClientError     error
	QueueError      error
	NetworkError    error

	Session            *Session
	Client             *Client
	Network            *DependencyNetwork
	Queue              amboy.Queue
	SetupClient        client.Client
	SetupSession       db.Session
	Closers            []func() error
	DependencyManagers map[string]*DependencyManager
	MigrationRegistry  map[string]client.MigrationOperation
	ProcessorRegistry  map[string]client.Processor
	MetaNS             model.Namespace
}

func NewEnvironment

func NewEnvironment() *Environment

func (*Environment) Close

func (e *Environment) Close() error

func (*Environment) GetClient

func (e *Environment) GetClient() (client.Client, error)

func (*Environment) GetDependencyNetwork

func (e *Environment) GetDependencyNetwork() (model.DependencyNetworker, error)

func (*Environment) GetDocumentProcessor

func (e *Environment) GetDocumentProcessor(name string) (client.Processor, bool)

func (*Environment) GetManualMigrationOperation

func (e *Environment) GetManualMigrationOperation(name string) (client.MigrationOperation, bool)

func (*Environment) GetQueue

func (e *Environment) GetQueue() (amboy.Queue, error)

func (*Environment) GetSession

func (e *Environment) GetSession() (db.Session, error)

func (*Environment) MetadataNamespace

func (e *Environment) MetadataNamespace() model.Namespace

func (*Environment) NewDependencyManager

func (e *Environment) NewDependencyManager(n string) dependency.Manager

func (*Environment) RegisterCloser

func (e *Environment) RegisterCloser(closer func() error)

func (*Environment) RegisterDocumentProcessor

func (e *Environment) RegisterDocumentProcessor(name string, docp client.Processor) error

func (*Environment) RegisterManualMigrationOperation

func (e *Environment) RegisterManualMigrationOperation(name string, op client.MigrationOperation) error

func (*Environment) Setup

func (e *Environment) Setup(q amboy.Queue, cl client.Client, session db.Session) 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 MigrationHelper

type MigrationHelper struct {
	Environment             Environment
	MigrationEvents         []*model.MigrationMetadata
	SaveMigrationEventError error
	NumPendingMigrations    int
	GetMigrationEventsIter  *Iterator
	GetMigrationEventsError error
}

func (*MigrationHelper) Env

func (m *MigrationHelper) Env() Environment

func (*MigrationHelper) FinishMigration

func (m *MigrationHelper) FinishMigration(name string, j *job.Base)

func (*MigrationHelper) GetMigrationEvents

func (m *MigrationHelper) GetMigrationEvents(_ map[string]interface{}) (db.Iterator, error)

func (*MigrationHelper) PendingMigrationOperations

func (m *MigrationHelper) PendingMigrationOperations(_ model.Namespace, _ map[string]interface{}) int

func (*MigrationHelper) SaveMigrationEvent

func (m *MigrationHelper) SaveMigrationEvent(data *model.MigrationMetadata) error

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 Processor

type Processor struct {
	NS                      model.Namespace
	Query                   map[string]interface{}
	Cursor                  client.Cursor
	MigrateError            error
	LastMigrateCallMismatch bool
	NumMigrateCalls         int
}

func (*Processor) Load

func (p *Processor) Load(cl client.Client, ns model.Namespace, query map[string]interface{}) client.Cursor

func (*Processor) Migrate

func (p *Processor) Migrate(cursor client.Cursor) 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) DecodeBytes

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

func (*SingleResult) Err

func (sr *SingleResult) Err() error

Jump to

Keyboard shortcuts

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