Version: v0.0.0-...-51f9457 Latest Latest

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 25 Imported by: 0



Package spantest implements: * start/stop the Cloud Spanner Emulator, * creation/removal of a temporary gcloud config, * creation of a temporary Spanner instance, * creation/destruction of a temporary Spanner database.



This section is empty.


This section is empty.


func SanitizeDBName

func SanitizeDBName(name string) string

SanitizeDBName tranforms name to a valid one. If name is already valid, returns it without changes.


type Emulator

type Emulator struct {
	// contains filtered or unexported fields

Emulator is for starting and stopping a Cloud Spanner Emulator process. TODO( Make Emulator an interfact with two implementations (*nativeEmulator and *dockerEmulator).

func StartEmulator

func StartEmulator(ctx context.Context) (*Emulator, error)

StartEmulator starts a Cloud Spanner Emulator instance.

func (*Emulator) NewInstance

func (e *Emulator) NewInstance(ctx context.Context, projectName string) (string, error)

NewInstance creates a temporary instance using Cloud Spanner Emulator.

func (*Emulator) Stop

func (e *Emulator) Stop() error

Stop kills the emulator process and removes the temporary gcloud config directory.

type TempDB

type TempDB struct {
	Name string
	// contains filtered or unexported fields

TempDB is a temporary Spanner database.

func NewTempDB

func NewTempDB(ctx context.Context, cfg TempDBConfig, e *Emulator) (*TempDB, error)

NewTempDB creates a temporary database with a random name. The caller is responsible for calling Drop on the returned TempDB to cleanup resources after usage. Unless it uses Cloud Spanner Emulator, then the database will be dropped when emulator stops.

func (*TempDB) Client

func (db *TempDB) Client(ctx context.Context) (*spanner.Client, error)

Client returns a spanner client connected to the database.

func (*TempDB) Drop

func (db *TempDB) Drop(ctx context.Context) error

Drop deletes the database.

type TempDBConfig

type TempDBConfig struct {
	// InstanceName is the name of Spannner instance where to create the
	// temporary database.
	// Format: projects/{project}/instances/{instance}.
	// Defaults to chromeinfra.TestSpannerInstance.
	InstanceName string

	// InitScriptPath is a path to a DDL script to initialize the database.
	// In lieu of a proper DDL parser, it is parsed using regexes.
	// Therefore the script MUST:
	//   - Use `#“ and/or `--“ for comments. No block comments.
	//   - Separate DDL statements with `;\n`.
	// If empty, the database is created with no tables.
	InitScriptPath string

TempDBConfig specifies how to create a temporary database.

Jump to

Keyboard shortcuts

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