ddbmock

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	// DeleteErr causes Delete() to return an error if it is set
	DeleteErr error
	// PutErr causes Put() to return an error if it is set
	PutErr error
	// PutBatchErr causes PutBatch() to return an error if it is set
	PutBatchErr error
	// DeleteBatchErr causes DeleteBatch() to return an error if it is set
	DeleteBatchErr error
	// TransactWriteItemsErr causes TransactWriteItems() to return an error if it is set
	TransactWriteItemsErr error
	// TransactionExecuteError causes Transaction objects created from this client
	// to fail with this error if set.
	TransactionExecuteErr error
	// contains filtered or unexported fields
}

Client is a mock client which can be used to test ddb queries.

func New

func New(t TestReporter) *Client

New creates a new mock client which satisfies the ddb.Storage interface.

func (*Client) Client added in v0.15.0

func (m *Client) Client() *dynamodb.Client

Client returns nil. If you're writing tests which use DynamoDB implementation details you should probably be using integration tests!

func (*Client) Delete added in v0.7.0

func (m *Client) Delete(ctx context.Context, item ddb.Keyer) error

func (*Client) DeleteBatch added in v0.13.0

func (m *Client) DeleteBatch(ctx context.Context, items ...ddb.Keyer) error

func (*Client) Get added in v0.15.0

func (m *Client) Get(ctx context.Context, key ddb.GetKey, item ddb.Keyer, opts ...func(*ddb.GetOpts)) (*ddb.GetItemResult, error)

Get returns mock query results based registered mock values.

func (*Client) MockGet added in v0.15.0

func (m *Client) MockGet(key ddb.GetKey, result interface{})

MockGet mocks a DynamoDB Get operation. The contents of the provided query will be used as the results.

For example:

db := ddbmock.New()
db.MockGet(ddb.GetKey{PK: "1", SK: "1"}, Apple{Color: "red"})

var got Apple
db.Get(ctx, ddb.GetKey{PK: "1", SK: "1"}, &got)
// got now contains {Result: Apple{Color: "red"}} as defined by MockGet.

func (*Client) MockQuery added in v0.5.0

func (m *Client) MockQuery(qb ddb.QueryBuilder)

MockQuery mocks a DynamoDB query. The contents of the provided query will be used as the results.

For example:

db := ddbmock.New()
db.MockQuery(&getApple{Result: Apple{Color: "red"}})

var got getApple
db.Query(ctx, &got)
// got now contains {Result: Apple{Color: "red"}} as defined by MockQuery.

func (*Client) MockQueryWithErr added in v0.5.0

func (m *Client) MockQueryWithErr(qb ddb.QueryBuilder, err error)

MockQueryWithErr mocks a DynamoDB query. It works the same as MockQuery, but allows an error response to be set. The err argument can be nil, in which case a nil error is returned. The contents of the provided query will be used as the results.

For example:

db := ddbmock.New()
db.MockQueryWithErr(&getApple{}, ddb.ErrNoItems)

var got getApple
err := db.Query(ctx, &got)
// err is equal to ddb.ErrNoItems.

func (*Client) MockQueryWithErrWithResult added in v0.9.0

func (m *Client) MockQueryWithErrWithResult(qb ddb.QueryBuilder, res *ddb.QueryResult, err error)

MockQueryWithErrWithResult mocks a DynamoDB query. It works the same as MockQueryWithErr, but allows a QueryResult to be set. The QueryResult argument can be nil, in which case a nil QueryResult is returned.

func (*Client) NewTransaction added in v0.15.0

func (m *Client) NewTransaction() ddb.Transaction

func (*Client) Put

func (m *Client) Put(ctx context.Context, item ddb.Keyer) error

func (*Client) PutBatch

func (m *Client) PutBatch(ctx context.Context, items ...ddb.Keyer) error

func (*Client) Query

func (m *Client) Query(ctx context.Context, qb ddb.QueryBuilder, opts ...func(*ddb.QueryOpts)) (*ddb.QueryResult, error)

Query returns mock query results based on the type of the 'qb' argument.

func (*Client) Table added in v0.15.0

func (m *Client) Table() string

func (*Client) TransactWriteItems added in v0.6.0

func (m *Client) TransactWriteItems(ctx context.Context, tx []ddb.TransactWriteItem) error

type MockTransaction added in v0.15.0

type MockTransaction struct {
	// ExecuteError causes Execute() to return with an error if set
	ExecuteError error
}

func (*MockTransaction) Delete added in v0.15.0

func (m *MockTransaction) Delete(item ddb.Keyer)

func (*MockTransaction) Execute added in v0.15.0

func (m *MockTransaction) Execute(ctx context.Context) error

func (*MockTransaction) Put added in v0.15.0

func (m *MockTransaction) Put(item ddb.Keyer)

type TestReporter added in v0.5.0

type TestReporter interface {
	Fatalf(format string, args ...interface{})
}

A TestReporter is something that can be used to report test failures. It is satisfied by the standard library's *testing.T.

Jump to

Keyboard shortcuts

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