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 ¶
- Variables
- func CreateSchema[P types.AnyPool](ctx *stopper.Context, pool P, prefix string) (ident.Schema, error)
- func GetRowCount[P types.AnyPool](ctx context.Context, db P, name ident.Table) (int, error)
- func ProvideContext(t testing.TB) *stopper.Context
- func ProvideSourcePool(ctx *stopper.Context, diags *diag.Diagnostics) (*types.SourcePool, error)
- func ProvideSourceSchema(ctx *stopper.Context, pool *types.SourcePool) (sinktest.SourceSchema, error)
- func ProvideStagingPool(ctx *stopper.Context) (*types.StagingPool, error)
- func ProvideStagingSchema(ctx *stopper.Context, pool *types.StagingPool) (ident.StagingSchema, error)
- func ProvideTargetPool(ctx *stopper.Context, source *types.SourcePool, diags *diag.Diagnostics) (*types.TargetPool, error)
- func ProvideTargetSchema(ctx *stopper.Context, diags *diag.Diagnostics, pool *types.TargetPool, ...) (sinktest.TargetSchema, error)
- func ProvideTargetStatements(ctx *stopper.Context, pool *types.TargetPool) *types.TargetStatements
- type Fixture
- type TableInfo
- func (ti TableInfo[P]) DeleteAll(ctx context.Context) error
- func (ti TableInfo[P]) DropTable(ctx context.Context) error
- func (ti TableInfo[P]) Exec(ctx context.Context, sql string, args ...any) error
- func (ti TableInfo[P]) Name() ident.Table
- func (ti TableInfo[P]) RowCount(ctx context.Context) (int, error)
- func (ti TableInfo[P]) String() string
Constants ¶
This section is empty.
Variables ¶
var TestSet = wire.NewSet( ProvideContext, ProvideStagingSchema, ProvideStagingPool, ProvideSourcePool, ProvideSourceSchema, ProvideTargetPool, ProvideTargetSchema, ProvideTargetStatements, diag.New, wire.Bind(new(context.Context), new(*stopper.Context)), wire.Struct(new(Fixture), "*"), )
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 ¶
GetRowCount returns the number of rows in the table.
func ProvideContext ¶
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 _replicator database. StagingDB ident.StagingSchema // The _replicator 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 ¶
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 ¶
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 ¶
NewTableInfo constructs a TableInfo using the given name.
func (TableInfo[P]) Exec ¶
Exec executes a single SQL statement. The sql string must include a single string substitution marker to receive the table name.