dbtest

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(ctx context.Context, t *testing.T, connectionString string) *sql.DB

Connect connects to the test database and returns the connection. It also sets up a cleanup function to close the connection after the test is complete.

func Migrate

func Migrate(url string, dir fs.FS) error

Types

type PostgresContainer

type PostgresContainer struct {
	*postgres.PostgresContainer
	ConnectionString string
}

func SetupPostgres

func SetupPostgres(t *testing.T, dbName string, setup func(connectionString string) error) *PostgresContainer

SetupPostgres sets up a test database and runs the provided setup function. It also sets up a cleanup function to terminate the container after the test is complete.

type Query

type Query struct {
	Query string
	Args  []interface{}
}

type Recorder

type Recorder struct {
	Queries     []Query
	RowQueries  []Query
	ExecQueries []Query
	// contains filtered or unexported fields
}

Recorder records all queries and arguments that are passed to the database.

func NewRecorder

func NewRecorder(dbConn database.Conn) *Recorder

NewRecorder creates a new query Recorder.

func (*Recorder) Exec

func (d *Recorder) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*Recorder) Query

func (d *Recorder) Query(ctx context.Context, query string, args ...interface{}) (*database.Rows, error)

func (*Recorder) QueryRow

func (d *Recorder) QueryRow(ctx context.Context, query string, args ...interface{}) *database.Row

Jump to

Keyboard shortcuts

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