testing

package
v0.0.0-...-b9bb202 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstFactory

func ConstFactory(runner coredatabase.TxnRunner) func() (changestream.WatchableDB, error)

ConstFactory returns a changestream.WatchableDB factory function from just a database.TxnRunner.

func DumpTable

func DumpTable(c *gc.C, db *sql.DB, table string, extraTables ...string)

DumpTable dumps the contents of the given table to stdout. This is useful for debugging tests. It is not intended for use in production code.

func FindTCPPort

func FindTCPPort(c *gc.C) int

FindTCPPort finds an unused TCP port and returns it. It is prone to racing, so the port should be used as soon as it is acquired to minimise the change of another process using it in the interim. The chances of this should be negligible during testing.

func SingularDBGetter

func SingularDBGetter(runner coredatabase.TxnRunner) coredatabase.DBGetter

SingularDBGetter returns a DBGetter that always returns the given database.

Types

type DqliteSuite

type DqliteSuite struct {
	testing.IsolationSuite

	// Verbose indicates whether the suite should print all the sql
	// hitting the db.
	Verbose bool

	// UseTCP when true, SetUpTest will use a random TCP port.
	// When false, it will use a random UNIX abstract domain socket.
	UseTCP bool
	// contains filtered or unexported fields
}

DqliteSuite is used to provide a sql.DB reference to tests. It is not pre-populated with any schema and is the job the users of this Suite to call ApplyDDL after SetupTest has been called.

func (*DqliteSuite) ApplyDDL

func (s *DqliteSuite) ApplyDDL(c *gc.C, schema SchemaApplier)

ApplyDDL is a helper manager for the test suites to apply a set of DDL string on top of a pre-established database.

func (*DqliteSuite) ApplyDDLForRunner

func (s *DqliteSuite) ApplyDDLForRunner(c *gc.C, schema SchemaApplier, runner coredatabase.TxnRunner)

ApplyDDLForRunner is a helper manager for the test suites to apply a set of DDL string on top of a pre-established database.

func (*DqliteSuite) DB

func (s *DqliteSuite) DB() *sql.DB

DB returns a sql.DB reference.

func (*DqliteSuite) DBApp

func (s *DqliteSuite) DBApp() *app.App

DBApp returns the dqlite app.

func (*DqliteSuite) DBPath

func (s *DqliteSuite) DBPath() string

DBPath returns the path to the dqlite database.

func (*DqliteSuite) NoopTxnRunner

func (s *DqliteSuite) NoopTxnRunner() coredatabase.TxnRunner

NoopTxnRunner returns a no-op transaction runner. Each call to this function will return the same instance, which will return a not implemented error when used.

func (*DqliteSuite) OpenDB

func (s *DqliteSuite) OpenDB(c *gc.C) (coredatabase.TxnRunner, *sql.DB)

OpenDB returns a new sql.DB reference.

func (*DqliteSuite) OpenDBForNamespace

func (s *DqliteSuite) OpenDBForNamespace(c *gc.C, domain string, foreignKey bool) (coredatabase.TxnRunner, *sql.DB)

OpenDBForNamespace returns a new sql.DB reference for the domain.

func (*DqliteSuite) RootPath

func (s *DqliteSuite) RootPath() string

RootPath returns the root path for the dqlite database.

func (*DqliteSuite) SetUpTest

func (s *DqliteSuite) SetUpTest(c *gc.C)

SetUpTest creates a new sql.DB reference and ensures that the controller schema is applied successfully.

func (*DqliteSuite) TearDownTest

func (s *DqliteSuite) TearDownTest(c *gc.C)

TearDownTest is responsible for cleaning up the testing resources created with the ControllerSuite

func (*DqliteSuite) TxnRunner

func (s *DqliteSuite) TxnRunner() coredatabase.TxnRunner

TxnRunner returns the suite's transaction runner.

func (*DqliteSuite) TxnRunnerFactory

func (s *DqliteSuite) TxnRunnerFactory() func() (coredatabase.TxnRunner, error)

TxnRunnerFactory returns a DBFactory that returns the given database.

type SchemaApplier

type SchemaApplier interface {
	Apply(c *gc.C, ctx context.Context, runner coredatabase.TxnRunner)
}

SchemaApplier is an interface that can be used to apply a schema to a database.

type TestTrackedDB

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

func NewTestTrackedDB

func NewTestTrackedDB(f coredatabase.TxnRunnerFactory) *TestTrackedDB

NewTestTrackedDB returns a tracked db worker which returns a tracked db attached to the test suite.

func (*TestTrackedDB) Kill

func (t *TestTrackedDB) Kill()

func (*TestTrackedDB) StdTxn

func (t *TestTrackedDB) StdTxn(ctx context.Context, fn func(context.Context, *sql.Tx) error) error

func (*TestTrackedDB) Txn

func (t *TestTrackedDB) Txn(ctx context.Context, fn func(context.Context, *sqlair.TX) error) error

func (*TestTrackedDB) Wait

func (t *TestTrackedDB) Wait() error

Jump to

Keyboard shortcuts

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