Documentation
¶
Overview ¶
Package firestoretest is an in-process Datastore server for the framework's own Firestore stores.
It exists because the gcloud Datastore emulator is a Java process inside the Cloud SDK image, which is too heavy to require of a unit test, and because contention cannot be provoked against it reliably. This server is small enough to state what it does and does not implement, which a test can then rely on.
It implements lookup, commit, beginTransaction, rollback and runQuery over an in-memory map. Transactions are serialized: one is open at a time, and a commit whose base versions moved is reported as ABORTED, which is what the driver re-runs a closure for. Queries evaluate equality filters over one kind and nothing else, because that is every query the framework stores issue.
Index ¶
- type Server
- func (fake *Server) BeforeCommit(fn func())
- func (fake *Server) Calls(op string) int
- func (fake *Server) Endpoint() string
- func (fake *Server) FailNext(status string)
- func (fake *Server) Len(kind string) int
- func (fake *Server) Namespaces() []string
- func (fake *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
Server is a running fake. Close it with the test's cleanup.
func New ¶
func New(tb interface {
Cleanup(func())
Helper()
}) *Server
New starts a fake and registers its shutdown with the test.
func (*Server) BeforeCommit ¶
func (fake *Server) BeforeCommit(fn func())
BeforeCommit runs fn inside the server lock, just before a commit is applied.
It is how a test provokes the race a version precondition exists to catch: the hook writes the entity the caller read, so the commit arrives with a base version that has already moved.
func (*Server) FailNext ¶
FailNext makes the next operation answer with status, which must be a canonical code name such as UNAVAILABLE or ABORTED.
func (*Server) Namespaces ¶
Namespaces reports the namespaces holding at least one entity, which is what an isolation test asserts on.