package dsiface

import "github.com/googleapis/google-cloud-go-testing/datastore/dsiface"

Package dsiface provides a set of interfaces for the types in cloud.google.com/go/datastore. These can be used to create mocks or other test doubles. The package also provides adapters to enable the types of the datastore package to implement these interfaces.

We do not recommend using mocks for most testing. Please read https://testing.googleblog.com/2013/05/testing-on-toilet-dont-overuse-mocks.html.

Note: This package is in alpha. Some backwards-incompatible changes may occur.

You must embed these interfaces to implement them:

type ClientMock struct {
    dsiface.Client
    ...
}

This ensures that your implementations will not break when methods are added to the interfaces.

Index

Types

type Client

type Client interface {
	Close() error
	AllocateIDs(ctx context.Context, keys []*datastore.Key) ([]*datastore.Key, error)
	Count(ctx context.Context, q *datastore.Query) (n int, err error)
	Delete(ctx context.Context, key *datastore.Key) error
	DeleteMulti(ctx context.Context, keys []*datastore.Key) (err error)
	Get(ctx context.Context, key *datastore.Key, dst interface{}) (err error)
	GetAll(ctx context.Context, q *datastore.Query, dst interface{}) (keys []*datastore.Key, err error)
	GetMulti(ctx context.Context, keys []*datastore.Key, dst interface{}) (err error)
	Mutate(ctx context.Context, muts ...*datastore.Mutation) (ret []*datastore.Key, err error)
	NewTransaction(ctx context.Context, opts ...datastore.TransactionOption) (t Transaction, err error)
	Put(ctx context.Context, key *datastore.Key, src interface{}) (*datastore.Key, error)
	PutMulti(ctx context.Context, keys []*datastore.Key, src interface{}) (ret []*datastore.Key, err error)
	Run(ctx context.Context, q *datastore.Query) Iterator
	RunInTransaction(ctx context.Context, f func(tx Transaction) error, opts ...datastore.TransactionOption) (cmt Commit, err error)
	// contains filtered or unexported methods
}

Client is the interface that wraps a datastore.Client.

func AdaptClient

func AdaptClient(c *datastore.Client) Client

AdaptClient adapts a datastore.Client so that it satisfies the Client interface.

type Commit

type Commit interface {
	Key(p *datastore.PendingKey) *datastore.Key
	// contains filtered or unexported methods
}

Commit is the interface that wraps a datastore.Commit.

type Iterator

type Iterator interface {
	Cursor() (c datastore.Cursor, err error)
	Next(dst interface{}) (k *datastore.Key, err error)
	// contains filtered or unexported methods
}

Iterator is the interface that wraps a datastore.Iterator.

type Transaction

type Transaction interface {
	Commit() (c Commit, err error)
	Delete(key *datastore.Key) error
	DeleteMulti(keys []*datastore.Key) (err error)
	Get(key *datastore.Key, dst interface{}) (err error)
	GetMulti(keys []*datastore.Key, dst interface{}) (err error)
	Mutate(muts ...*datastore.Mutation) ([]*datastore.PendingKey, error)
	Put(key *datastore.Key, src interface{}) (*datastore.PendingKey, error)
	PutMulti(keys []*datastore.Key, src interface{}) (ret []*datastore.PendingKey, err error)
	Rollback() (err error)
	// contains filtered or unexported methods
}

Transaction is the interface that wraps a datastore.Transaction.

Source Files

adapters.go doc.go interfaces.go

Version
v0.0.0-20210719221736-1c9a4c676720 (latest)
Published
Jul 19, 2021
Platform
linux/amd64
Imports
2 packages
Last checked
3 weeks ago

Tools for package owners.