Documentation ¶
Overview ¶
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.
Index ¶
Constants ¶
const ( // IntegrationTestEnvVar is the name of the environment variable which controls // whether spanner tests are executed. // The value must be "1" for integration tests to run. IntegrationTestEnvVar = "INTEGRATION_TESTS" )
Variables ¶
This section is empty.
Functions ¶
func SanitizeDBName ¶
SanitizeDBName tranforms name to a valid one. If name is already valid, returns it without changes.
func SpannerTestContext ¶
func SpannerTestContext(tb testing.TB, cleanupDatabase CleanupDatabase) context.Context
SpannerTestContext returns a context for testing code that talks to Spanner. Skips the test if integration tests are not enabled.
Tests that use Spanner MUST NOT call t.Parallel().
func SpannerTestMain ¶
func SpannerTestMain(m *testing.M, findInitScript FindInitScript)
SpannerTestMain is a test main function for packages that have tests that talk to spanner. It creates/destroys a temporary spanner database before/after running tests.
This function never returns. Instead it calls os.Exit with the value returned by m.Run().
Types ¶
type CleanupDatabase ¶
CleanupDatabase deletes all data from all tables.
type Emulator ¶
type Emulator struct {
// contains filtered or unexported fields
}
Emulator is for starting and stopping a Cloud Spanner Emulator process. TODO(crbug.com/1066993): Make Emulator an interfact with two implementations (*nativeEmulator and *dockerEmulator).
func StartEmulator ¶
StartEmulator starts a Cloud Spanner Emulator instance.
func (*Emulator) NewInstance ¶
NewInstance creates a temporary instance using Cloud Spanner Emulator.
type FindInitScript ¶
FindInitScript returns path to a .sql file which contains the schema of the tested Spanner database.
type TempDB ¶
type TempDB struct { Name string // contains filtered or unexported fields }
TempDB is a temporary Spanner database.
func NewTempDB ¶
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.
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.