dynamofake

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 14 Imported by: ? 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 dynamofake is a fake of the DynamoDB service for the tests of the DynamoDB flag source: an HTTP server on a loopback port that speaks the JSON protocol of the service and answers Scan from tables it keeps in memory, a page at a time. It can refuse a request by a script (a status and an error code), check the access key of the signature, and it records the requests. What it models is from the documentation of the protocol and the behaviour of the Go client; it is no DynamoDB: the docker tests of the flag source run an emulator.

Index

Constants

View Source
const (

	// DefaultPageSize is the number of items of a page of Scan unless [Server.SetPageSize] says otherwise.
	DefaultPageSize = 100
)

Variables

This section is empty.

Functions

func Transport

func Transport(tb testing.TB) http.RoundTripper

Transport is the HTTP transport for the clients that talk to a fake. It sends each request body from a copy of its own. Without it, a held answer can fail a request by chance: the AWS SDK closes the body of a request as soon as the answer starts, and the Go client, which may still be writing the end of the body (it copies it twice, the second time to find extra bytes), then fails the write, closes the connection and so cuts the answer that is being read ("use of closed network connection"). A real service answers later than the client needs to finish the write, and the SDK retries such a failure; a fake that answers at once, with a test that allows one attempt, needs this transport. The connections are closed when the test ends.

Types

type Failure

type Failure struct {
	Code    string
	Message string
	Status  int
}

Failure is a scripted refusal: the status, the error code of the service and its message.

type Request

type Request struct {
	// Target is the operation, for example DynamoDB_20120810.Scan.
	Target string
	// Table is the table of the request.
	Table string
	// AccessKey is the access key id of the signature, empty for an unsigned request.
	AccessKey string
	// ConsistentRead is the setting of the request.
	ConsistentRead bool
	// Continued tells that the request asks for a page after the first.
	Continued bool
}

Request is what the fake saw of one request.

type Server

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

Server is a fake DynamoDB service. All its methods are safe for concurrent use.

func New

func New(tb testing.TB) *Server

New starts a fake and stops it when the test ends. The listener is open from the start.

func (*Server) DeleteTable

func (s *Server) DeleteTable(name string)

DeleteTable removes the table.

func (*Server) Fail

func (s *Server) Fail(failures ...Failure)

Fail scripts the answers of the next requests, in order: each request takes the first failure that is left.

func (*Server) Requests

func (s *Server) Requests() []Request

Requests are the requests seen so far, in order.

func (*Server) RequireAccessKey

func (s *Server) RequireAccessKey(key string)

RequireAccessKey makes the fake refuse a request that is not signed with the access key id.

func (*Server) SetEndless

func (s *Server) SetEndless(name string)

SetEndless makes Scan of the table answer without end: pages with no item and a cursor for the next one.

func (*Server) SetPageSize

func (s *Server) SetPageSize(size int)

SetPageSize sets the number of items of a page of Scan.

func (*Server) SetTable

func (s *Server) SetTable(name string, items ...string)

SetTable creates the table, or replaces its items. An item is the JSON of its attributes in the typed form of the service, for example {"flag":{"S":"a"},"on":{"BOOL":true}}. The items are kept, and answered, in the order given.

func (*Server) StallFrom

func (s *Server) StallFrom(request int)

StallFrom makes the fake hold the answer of the nth request and of every later one (counted from 1): it sends the status and the headers and then no body, until the client gives up. Zero turns it off.

func (*Server) URL

func (s *Server) URL() string

URL is the endpoint of the service.

Jump to

Keyboard shortcuts

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