dsiface

package
v0.0.0-...-1c9a4c6 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: Apache-2.0 Imports: 2 Imported by: 1

README

Datastore

Run Tests

Run unit tests

The unit tests run locally against an example fake and do not require any configuration.

go test --short
Run all tests

The integration tests will reach out and store, read and then delete a value from a datastore. You have to provide the DATASTORE_PROJECT_ID environment variable and the client has to be able to find credentials.

For example:

DATASTORE_PROJECT_ID=<proj-id> GOOGLE_APPLICATION_CREDENTIALS=</path/to/creds.json> go test

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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.

Jump to

Keyboard shortcuts

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