- 1.69.0 (latest)
- 1.68.0
- 1.67.0
- 1.66.0
- 1.65.0
- 1.64.0
- 1.63.0
- 1.62.0
- 1.61.0
- 1.60.0
- 1.59.0
- 1.58.0
- 1.57.0
- 1.56.0
- 1.55.0
- 1.54.0
- 1.53.1
- 1.52.0
- 1.49.0
- 1.48.0
- 1.47.0
- 1.46.0
- 1.45.1
- 1.44.0
- 1.43.0
- 1.42.0
- 1.41.0
- 1.40.0
- 1.39.0
- 1.38.0
- 1.37.0
- 1.36.0
- 1.35.0
- 1.34.1
- 1.33.0
- 1.32.0
- 1.31.0
- 1.30.1
- 1.29.0
- 1.28.0
- 1.27.0
- 1.26.0
- 1.25.0
- 1.24.1
- 1.23.0
- 1.22.0
- 1.21.0
- 1.20.0
- 1.19.0
- 1.18.0
- 1.17.0
- 1.16.0
- 1.15.0
- 1.14.1
- 1.13.0
Package spannertest contains test helpers for working with Cloud Spanner.
This package is EXPERIMENTAL, and is lacking several features. See the README.md file in this directory for more details.
In-memory fake
This package has an in-memory fake implementation of spanner. To use it, create a Server, and then connect to it with no security:
srv, err := spannertest.NewServer("localhost:0") ... conn, err := grpc.DialContext(ctx, srv.Addr, grpc.WithInsecure()) ... client, err := spanner.NewClient(ctx, db, option.WithGRPCConn(conn)) ...
Alternatively, create a Server, then set the SPANNER_EMULATOR_HOST environment variable and use the regular spanner.NewClient:
srv, err := spannertest.NewServer("localhost:0") ... os.Setenv("SPANNER_EMULATOR_HOST", srv.Addr) client, err := spanner.NewClient(ctx, db) ...
The same server also supports database admin operations for use with the cloud.google.com/go/spanner/admin/database/apiv1 package. This only simulates the existence of a single database; its name is ignored.
Logger
type Logger func(format string, args ...interface{})
Logger is something that can be used for logging. It is matched by log.Printf and testing.T.Logf.
Server
type Server struct {
Addr string
// contains filtered or unexported fields
}
Server is an in-memory Cloud Spanner fake. It is unauthenticated, non-performant, and only a rough approximation.
func NewServer
NewServer creates a new Server. The Server will be listening for gRPC connections, without TLS, on the provided TCP address. The resolved address is available in the Addr field.
func (*Server) Close
func (s *Server) Close()
Close shuts down the server.
func (*Server) SetLogger
SetLogger sets a logger for the server. You can use a *testing.T as this argument to collate extra information from the execution of the server.
func (*Server) UpdateDDL
UpdateDDL applies the given DDL to the server.
This is a convenience method for tests that may assume an existing schema. The more general approach is to dial this server using an admin client, and use the UpdateDatabaseDdl RPC method.