base

package
v0.0.0-...-9e054ec Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package base provides enough functionality to connect to a database, but does not provide any other services. This package is primary used to break dependency cycles in tests.

Index

Constants

This section is empty.

Variables

TestSet is used by wire.

Functions

func CreateSchema

func CreateSchema[P types.AnyPool](
	ctx *stopper.Context, pool P, prefix string,
) (ident.Schema, error)

CreateSchema creates a schema with a unique name that will be dropped when the stopper has stopped.

func GetRowCount

func GetRowCount[P types.AnyPool](ctx context.Context, db P, name ident.Table) (int, error)

GetRowCount returns the number of rows in the table.

func ProvideContext

func ProvideContext(t testing.TB) *stopper.Context

ProvideContext returns an execution context that is associated with a singleton connection to a CockroachDB cluster.

func ProvideSourcePool

func ProvideSourcePool(ctx *stopper.Context, diags *diag.Diagnostics) (*types.SourcePool, error)

ProvideSourcePool connects to the source database. If the source is a CockroachDB cluster, this function will also configure the rangefeed and license cluster settings if they have not been previously configured.

func ProvideSourceSchema

func ProvideSourceSchema(
	ctx *stopper.Context, pool *types.SourcePool,
) (sinktest.SourceSchema, error)

ProvideSourceSchema create a globally-unique container for tables in the source database.

func ProvideStagingPool

func ProvideStagingPool(ctx *stopper.Context) (*types.StagingPool, error)

ProvideStagingPool opens a connection to the CockroachDB staging cluster under test.

func ProvideStagingSchema

func ProvideStagingSchema(
	ctx *stopper.Context, pool *types.StagingPool,
) (ident.StagingSchema, error)

ProvideStagingSchema create a globally-unique container for tables in the staging database.

func ProvideTargetPool

func ProvideTargetPool(
	ctx *stopper.Context, source *types.SourcePool, diags *diag.Diagnostics,
) (*types.TargetPool, error)

ProvideTargetPool connects to the target database (which is most often the same as the source database).

func ProvideTargetSchema

func ProvideTargetSchema(
	ctx *stopper.Context,
	diags *diag.Diagnostics,
	pool *types.TargetPool,
	stmts *types.TargetStatements,
) (sinktest.TargetSchema, error)

ProvideTargetSchema create a globally-unique container for tables in the target database.

func ProvideTargetStatements

func ProvideTargetStatements(ctx *stopper.Context, pool *types.TargetPool) *types.TargetStatements

ProvideTargetStatements is called by Wire to construct a prepared-statement cache. Anywhere the associated TargetPool is reused should also reuse the cache.

Types

type Fixture

type Fixture struct {
	Context      *stopper.Context        // The context for the test.
	SourcePool   *types.SourcePool       // Access to user-data tables and changefeed creation.
	SourceSchema sinktest.SourceSchema   // A container for tables within SourcePool.
	StagingPool  *types.StagingPool      // Access to __cdc_sink database.
	StagingDB    ident.StagingSchema     // The _cdc_sink SQL DATABASE.
	TargetCache  *types.TargetStatements // Prepared statements.
	TargetPool   *types.TargetPool       // Access to the destination.
	TargetSchema sinktest.TargetSchema   // A container for tables within TargetPool.
}

Fixture can be used for tests that "just need a database", without the other services provided by the target package. One can be constructed by calling NewFixture.

func NewFixture

func NewFixture(t testing.TB) (*Fixture, error)

NewFixture constructs a self-contained test fixture.

func (*Fixture) CreateSourceTable

func (f *Fixture) CreateSourceTable(
	ctx context.Context, schemaSpec string,
) (TableInfo[*types.SourcePool], error)

CreateSourceTable creates a test table within the SourcePool and SourceSchema. The schemaSpec parameter must have exactly one %s substitution parameter for the database name and table name.

func (*Fixture) CreateTargetTable

func (f *Fixture) CreateTargetTable(
	ctx context.Context, schemaSpec string,
) (TableInfo[*types.TargetPool], error)

CreateTargetTable creates a test table within the TargetPool and TargetSchema. The schemaSpec parameter must have exactly one %s substitution parameter for the database name and table name.

type TableInfo

type TableInfo[P types.AnyPool] struct {
	// contains filtered or unexported fields
}

TableInfo provides a named table and a means to access it. Instances are created via CreateTable.

func CreateTable

func CreateTable[P types.AnyPool](
	ctx context.Context, pool P, enclosing ident.Schema, schemaSpec string,
) (TableInfo[P], error)

CreateTable creates a test table. The schemaSpec parameter must have exactly one %s substitution parameter for the database name and table name.

func NewTableInfo

func NewTableInfo[P types.AnyPool](db P, name ident.Table) TableInfo[P]

NewTableInfo constructs a TableInfo using the given name.

func (TableInfo[P]) DeleteAll

func (ti TableInfo[P]) DeleteAll(ctx context.Context) error

DeleteAll deletes (not TRUNCATEs) all rows in the table.

func (TableInfo[P]) DropTable

func (ti TableInfo[P]) DropTable(ctx context.Context) error

DropTable drops the table.

func (TableInfo[P]) Exec

func (ti TableInfo[P]) Exec(ctx context.Context, sql string, args ...any) error

Exec executes a single SQL statement. The sql string must include a single string substitution marker to receive the table name.

func (TableInfo[P]) Name

func (ti TableInfo[P]) Name() ident.Table

Name returns the table name.

func (TableInfo[P]) RowCount

func (ti TableInfo[P]) RowCount(ctx context.Context) (int, error)

RowCount returns the number of rows in the table.

func (TableInfo[P]) String

func (ti TableInfo[P]) String() string

Jump to

Keyboard shortcuts

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