fakedb

package
v6.5.2-rc Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fakedb provides a deterministic, state-backed DynamoDBAPI fake for consumer tests.

The fake is a local testing aid. It is intentionally bounded to TableTheory's scenario-validated behavior and should not be treated as a DynamoDB emulator. Unlike the scripted doubles in pkg/mocks, it stores item state and evaluates supported condition expressions, including the partition-key not-exists guard used by Create.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fake

type Fake struct {
	// contains filtered or unexported fields
}

Fake is an in-memory implementation of the TableTheory DynamoDBAPI seam.

func New

func New() *Fake

New returns an empty in-memory DynamoDB fake. Use it for tests whose outcome depends on stored state or supported condition expressions; pkg/mocks does not evaluate those conditions. It keeps the fake's historical permissive TTL behavior; use NewWithOptions with WithDynamoDBTTLValidation to make UpdateTimeToLive reject what DynamoDB rejects.

func NewWithOptions added in v6.2.0

func NewWithOptions(options ...Option) *Fake

NewWithOptions returns an empty in-memory DynamoDB fake configured with the supplied options.

func (*Fake) BatchGetItem

func (f *Fake) BatchGetItem(_ context.Context, params *dynamodb.BatchGetItemInput, _ ...func(*dynamodb.Options)) (*dynamodb.BatchGetItemOutput, error)

func (*Fake) BatchWriteItem

func (f *Fake) BatchWriteItem(_ context.Context, params *dynamodb.BatchWriteItemInput, _ ...func(*dynamodb.Options)) (*dynamodb.BatchWriteItemOutput, error)

func (*Fake) CreateBackup

func (f *Fake) CreateBackup(_ context.Context, params *dynamodb.CreateBackupInput, _ ...func(*dynamodb.Options)) (*dynamodb.CreateBackupOutput, error)

func (*Fake) CreateTable

func (f *Fake) CreateTable(_ context.Context, params *dynamodb.CreateTableInput, _ ...func(*dynamodb.Options)) (*dynamodb.CreateTableOutput, error)

func (*Fake) DeleteItem

func (f *Fake) DeleteItem(_ context.Context, params *dynamodb.DeleteItemInput, _ ...func(*dynamodb.Options)) (*dynamodb.DeleteItemOutput, error)

func (*Fake) DeleteTable

func (f *Fake) DeleteTable(_ context.Context, params *dynamodb.DeleteTableInput, _ ...func(*dynamodb.Options)) (*dynamodb.DeleteTableOutput, error)

func (*Fake) DescribeTable

func (f *Fake) DescribeTable(_ context.Context, params *dynamodb.DescribeTableInput, _ ...func(*dynamodb.Options)) (*dynamodb.DescribeTableOutput, error)

func (*Fake) DescribeTimeToLive added in v6.2.0

func (f *Fake) DescribeTimeToLive(_ context.Context, params *dynamodb.DescribeTimeToLiveInput, _ ...func(*dynamodb.Options)) (*dynamodb.DescribeTimeToLiveOutput, error)

DescribeTimeToLive reports the TTL state the fake records from UpdateTimeToLive, matching the DynamoDB status and attribute shape.

func (*Fake) GetItem

func (f *Fake) GetItem(_ context.Context, params *dynamodb.GetItemInput, _ ...func(*dynamodb.Options)) (*dynamodb.GetItemOutput, error)

func (*Fake) Items

func (f *Fake) Items(tableName string) []map[string]types.AttributeValue

Items returns a deterministic snapshot of the table's stored items.

func (*Fake) ListTables

func (f *Fake) ListTables(_ context.Context, params *dynamodb.ListTablesInput, _ ...func(*dynamodb.Options)) (*dynamodb.ListTablesOutput, error)

func (*Fake) PutItem

func (f *Fake) PutItem(_ context.Context, params *dynamodb.PutItemInput, _ ...func(*dynamodb.Options)) (*dynamodb.PutItemOutput, error)

func (*Fake) Query

func (f *Fake) Query(_ context.Context, params *dynamodb.QueryInput, _ ...func(*dynamodb.Options)) (*dynamodb.QueryOutput, error)

func (*Fake) QueueTransactionCancellation

func (f *Fake) QueueTransactionCancellation(reasons []types.CancellationReason)

QueueTransactionCancellation makes every TransactWriteItems call fail with a synthesized TransactionCanceledException carrying the supplied reasons in position, until it is cleared. A nil slice clears any queued cancellation; an empty (non-nil) slice queues a cancellation with no reasons. It is a test seam for exercising the cancellation taxonomy without real DynamoDB.

func (*Fake) QueueTransactionError

func (f *Fake) QueueTransactionError(err error)

QueueTransactionError makes every TransactWriteItems call fail with err, returned unchanged, until it is cleared. A nil err clears any queued failure. It is a test seam for exercising non-cancellation (transport) failures against the same path.

func (*Fake) Reset

func (f *Fake) Reset()

Reset removes all fake tables and items and clears any queued transaction failure.

func (*Fake) Scan

func (f *Fake) Scan(_ context.Context, params *dynamodb.ScanInput, _ ...func(*dynamodb.Options)) (*dynamodb.ScanOutput, error)

func (*Fake) Seed

func (f *Fake) Seed(tableName string, items ...map[string]types.AttributeValue) error

Seed stores items in a table, creating a PK/SK shaped table when needed.

func (*Fake) TransactGetItems

func (f *Fake) TransactGetItems(_ context.Context, params *dynamodb.TransactGetItemsInput, _ ...func(*dynamodb.Options)) (*dynamodb.TransactGetItemsOutput, error)

func (*Fake) TransactWriteItems

func (f *Fake) TransactWriteItems(_ context.Context, params *dynamodb.TransactWriteItemsInput, _ ...func(*dynamodb.Options)) (*dynamodb.TransactWriteItemsOutput, error)

func (*Fake) UpdateItem

func (f *Fake) UpdateItem(_ context.Context, params *dynamodb.UpdateItemInput, _ ...func(*dynamodb.Options)) (*dynamodb.UpdateItemOutput, error)

func (*Fake) UpdateTable

func (f *Fake) UpdateTable(_ context.Context, params *dynamodb.UpdateTableInput, _ ...func(*dynamodb.Options)) (*dynamodb.UpdateTableOutput, error)

func (*Fake) UpdateTimeToLive

func (f *Fake) UpdateTimeToLive(_ context.Context, params *dynamodb.UpdateTimeToLiveInput, _ ...func(*dynamodb.Options)) (*dynamodb.UpdateTimeToLiveOutput, error)

type Option added in v6.2.0

type Option func(*Fake)

Option configures a Fake at construction time.

func WithDynamoDBTTLValidation added in v6.2.0

func WithDynamoDBTTLValidation() Option

WithDynamoDBTTLValidation makes UpdateTimeToLive reject the requests DynamoDB rejects: a missing TimeToLiveSpecification.AttributeName, enabling TTL on the attribute that is already enabled, and enabling TTL while another attribute is enabled. The default fake accepts all three, matching the behavior existing consumer tests rely on.

Jump to

Keyboard shortcuts

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