driver

package module
v0.0.0-...-ee2d29e Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: MIT Imports: 16 Imported by: 0

README

spanner-emulator-driver

Simple utility to run google's Spanner database emulator, aimed for testing purposes.

SYNOPSIS

import (
	"context"
	"testing"

	driver "github.com/lestrrat-go/spanner-emulator-driver"
	"github.com/stretchr/testify/require"
)

func TestDriver(t *testing.T) {
	dsn := driver.Config{
		Project:  `driver-test-project`,
		Instance: `driver-test-instance`,
		Database: `driver-test`,
	}

	d, err := driver.New(dsn.FormatDSN())
	require.NoError(t, err, `driver.New should succeed`)

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	exited := d.Run(ctx)

	require.NoError(t, d.Ready(ctx), `driver should start successfully`)

	// Your tests go here

	// Make sure to wait for the emulator to exit
	<-exited
}

Documentation

Overview

Package driver provides utilities to control Google's Spanner emulator for testing purposes.

Index

Constants

View Source
const (
	SPANNER_EMULATOR_HOST = `SPANNER_EMULATOR_HOST`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Project  string // Name of the project
	Instance string // Name of the instance
	Database string // Name of the database
}

Config is an utility object that works like `(github.com/go-sql-mysql).Config` which allows users to use existing tools to import connection information.

func ParseDSN

func ParseDSN(dsn string) (*Config, error)

func (*Config) FormatDSN

func (cfg *Config) FormatDSN() string

FormatDSN formats the given Config into a DSN string which can be passed to the spanner driver

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver is the main object to control the spanner emulator. The zero value should not be used. Always use the value returned from driver.New

func New

func New(dsn string) (*Driver, error)

func (*Driver) Close

func (d *Driver) Close()

func (*Driver) Ready

func (d *Driver) Ready(ctx context.Context) error

func (*Driver) Run

func (d *Driver) Run(ctx context.Context, options ...Option) <-chan error

Run controls the emulator running in docker. The environment variable SPANNER_EMULATOR_HOST will also be set to the appropriate value

type Option

type Option = option.Interface

func WithDDLDirectory

func WithDDLDirectory(dir string) Option

func WithDropDatabase

func WithDropDatabase(v bool) Option

func WithUseEmulator

func WithUseEmulator(v bool) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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