firestoretest

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	*httptest.Server
	// contains filtered or unexported fields
}

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) Calls

func (fake *Server) Calls(op string) int

Calls reports how many times one operation was served.

func (*Server) Endpoint

func (fake *Server) Endpoint() string

Endpoint is the address to configure a client with.

func (*Server) FailNext

func (fake *Server) FailNext(status string)

FailNext makes the next operation answer with status, which must be a canonical code name such as UNAVAILABLE or ABORTED.

func (*Server) Len

func (fake *Server) Len(kind string) int

Len reports how many entities of one kind are stored, over every namespace.

func (*Server) Namespaces

func (fake *Server) Namespaces() []string

Namespaces reports the namespaces holding at least one entity, which is what an isolation test asserts on.

func (*Server) ServeHTTP

func (fake *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request)

Jump to

Keyboard shortcuts

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