sqlitetest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package sqlitetest opens SQLite test databases with every connection rule of package sqlite on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckLibc

func CheckLibc(t testing.TB)

CheckLibc fails t when the build's modernc.org/libc differs from sqlite.LibcVersion.

func Open

func Open(t testing.TB, opts sqlite.Options) *sql.DB

Open returns a handle with opts on a new file in a fresh folder of t, closed when t ends.

func OpenWithFaults

func OpenWithFaults(t testing.TB, opts sqlite.Options, faults *Faults) *sql.DB

OpenWithFaults returns a handle like Open whose connections answer with the failures of faults.

Types

type Faults

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

Faults holds the failures the connections of a handle from OpenWithFaults answer with.

func (*Faults) FailNextCommit

func (f *Faults) FailNextCommit(err error)

FailNextCommit makes the next commit roll its transaction back and answer err.

func (*Faults) FailStatement

func (f *Faults) FailStatement(query string, err error)

FailStatement makes every statement whose text is exactly query answer err, inside transactions too.

func (*Faults) Pass

func (f *Faults) Pass(query string)

Pass stops failing the statement whose text is exactly query.

type Template

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

Template is a migrated and closed database file that each test opens a copy of.

func NewTemplate

func NewTemplate(
	ctx context.Context, opts sqlite.Options, migrate func(ctx context.Context, db *sql.DB) error,
) (tp *Template, err error)

NewTemplate returns a template migrated once under ctx by migrate with opts in a new file of its own temp folder.

func (*Template) Close

func (tp *Template) Close() error

Close removes the folder of the template, and Open fails every test after it.

func (*Template) Open

func (tp *Template) Open(t testing.TB) *sql.DB

Open returns a handle with every rule on a copy of the template in a fresh folder of t, closed when t ends.

func (*Template) OpenWithFaults

func (tp *Template) OpenWithFaults(t testing.TB, faults *Faults) *sql.DB

OpenWithFaults returns a handle like Open whose connections answer with the failures of faults.

Jump to

Keyboard shortcuts

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