mock

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

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

IMPORTANT: Mock driver only works with Go function migrations (UpFunc/DownFunc). SQL migrations (UpSQL/DownSQL) require a real database connection and will panic when used with the mock driver.

For testing SQL migrations, use a real database (e.g., postgres in Docker) or use the testcontainers library.

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.

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 mock driver (no-op).

func (*Driver) Exec

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

Exec executes a function (mock doesn't actually use transactions).

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) 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 (for testing).

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