spantest

package
v0.0.0-...-4a11b79 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package spantest implements creation/destruction of a temporary Spanner database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeDBName

func SanitizeDBName(name string) string

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

Types

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) (*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.

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

	// Credentials will be used to authenticate to Spanner.
	// If nil, auth.Authenticator with SilentLogin and chrome-infra auth options
	// will be used.
	// This means that that the user may have to login with luci-auth tool.
	Credentials credentials.PerRPCCredentials

	// 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