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
- func Transport(tb testing.TB) http.RoundTripper
- type Failure
- type Request
- type Server
- func (s *Server) DeleteTable(name string)
- func (s *Server) Fail(failures ...Failure)
- func (s *Server) Requests() []Request
- func (s *Server) RequireAccessKey(key string)
- func (s *Server) SetEndless(name string)
- func (s *Server) SetPageSize(size int)
- func (s *Server) SetTable(name string, items ...string)
- func (s *Server) StallFrom(request int)
- func (s *Server) URL() string
Constants ¶
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 ¶
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 (*Server) DeleteTable ¶
DeleteTable removes the table.
func (*Server) Fail ¶
Fail scripts the answers of the next requests, in order: each request takes the first failure that is left.
func (*Server) RequireAccessKey ¶
RequireAccessKey makes the fake refuse a request that is not signed with the access key id.
func (*Server) SetEndless ¶
SetEndless makes Scan of the table answer without end: pages with no item and a cursor for the next one.
func (*Server) SetPageSize ¶
SetPageSize sets the number of items of a page of Scan.
func (*Server) SetTable ¶
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.