mock

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package mock provides an in-memory mock driver for testing Queen without a real database.

This driver uses SQLite in-memory database to support both SQL and Go function migrations. SQL migrations are executed but data is not persisted (exists only in memory).

For integration testing with persistent data, use a real database driver instead (e.g., postgres, mysql, sqlite with file).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

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

Driver is an in-memory mock implementation of queen.Driver for testing.

func New

func New() *Driver

New creates a new mock driver with an in-memory SQLite database.

The in-memory database allows SQL migrations to be executed for testing, but data is not persisted and is lost when the driver is closed.

func (*Driver) AppliedCount

func (d *Driver) AppliedCount() int

AppliedCount returns the number of applied migrations (for testing).

func (*Driver) Close

func (d *Driver) Close() error

Close closes the in-memory database connection.

func (*Driver) Exec

func (d *Driver) Exec(ctx context.Context, isolationLevel sql.IsolationLevel, fn func(*sql.Tx) error) error

Exec executes a function within a real SQLite transaction with the specified isolation level.

This allows SQL migrations to be executed against the in-memory database.

func (*Driver) GetApplied

func (d *Driver) GetApplied(ctx context.Context) ([]queen.Applied, error)

GetApplied returns all applied migrations.

func (*Driver) HasVersion

func (d *Driver) HasVersion(version string) bool

HasVersion returns whether a specific version has been applied (for testing).

func (*Driver) Init

func (d *Driver) Init(ctx context.Context) error

Init initializes the mock driver.

func (*Driver) IsLocked

func (d *Driver) IsLocked() bool

IsLocked returns whether the driver is currently locked (for testing).

func (*Driver) Lock

func (d *Driver) Lock(ctx context.Context, timeout time.Duration) error

Lock acquires a lock.

func (*Driver) Record

func (d *Driver) Record(ctx context.Context, m *queen.Migration, meta *queen.MigrationMetadata) error

Record marks a migration as applied.

func (*Driver) Remove

func (d *Driver) Remove(ctx context.Context, version string) error

Remove removes a migration record.

func (*Driver) Reset

func (d *Driver) Reset()

Reset clears all applied migrations metadata (for testing).

Note: This only clears the migration tracking metadata. It does NOT reset the in-memory database schema or data. To reset the database, create a new mock driver instance.

func (*Driver) SetInitError

func (d *Driver) SetInitError(err error)

SetInitError makes Init return the specified error.

func (*Driver) SetLockError

func (d *Driver) SetLockError(err error)

SetLockError makes Lock return the specified error.

func (*Driver) SetRecordError

func (d *Driver) SetRecordError(err error)

SetRecordError makes Record return the specified error.

func (*Driver) Unlock

func (d *Driver) Unlock(ctx context.Context) error

Unlock releases the lock.

Jump to

Keyboard shortcuts

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