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 ¶
- type Driver
- func (d *Driver) AppliedCount() int
- func (d *Driver) Close() error
- func (d *Driver) Exec(ctx context.Context, isolationLevel sql.IsolationLevel, fn func(*sql.Tx) error) error
- func (d *Driver) GetApplied(ctx context.Context) ([]queen.Applied, error)
- func (d *Driver) HasVersion(version string) bool
- func (d *Driver) Init(ctx context.Context) error
- func (d *Driver) IsLocked() bool
- func (d *Driver) Lock(ctx context.Context, timeout time.Duration) error
- func (d *Driver) Record(ctx context.Context, m *queen.Migration, meta *queen.MigrationMetadata) error
- func (d *Driver) Remove(ctx context.Context, version string) error
- func (d *Driver) Reset()
- func (d *Driver) SetInitError(err error)
- func (d *Driver) SetLockError(err error)
- func (d *Driver) SetRecordError(err error)
- func (d *Driver) Unlock(ctx context.Context) error
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 ¶
AppliedCount returns the number of applied migrations (for testing).
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 ¶
GetApplied returns all applied migrations.
func (*Driver) HasVersion ¶
HasVersion returns whether a specific version has been applied (for testing).
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) 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 ¶
SetInitError makes Init return the specified error.
func (*Driver) SetLockError ¶
SetLockError makes Lock return the specified error.
func (*Driver) SetRecordError ¶
SetRecordError makes Record return the specified error.