Documentation
¶
Overview ¶
Package grovetest provides testing utilities for Grove applications. It includes a mock driver, fixture loader, and query assertion helpers.
Index ¶
- func AssertLastArgs(t *testing.T, d *MockDriver, expected ...any)
- func AssertLastQuery(t *testing.T, d *MockDriver, expected string)
- func AssertNoQueries(t *testing.T, d *MockDriver)
- func AssertQueryContains(t *testing.T, d *MockDriver, substring string)
- func AssertQueryCount(t *testing.T, d *MockDriver, n int)
- type Fixture
- type MockDialect
- func (d *MockDialect) AppendBytes(b, v []byte) []byte
- func (d *MockDialect) AppendTime(b []byte, t time.Time) []byte
- func (d *MockDialect) GoToDBType(goType reflect.Type, opts schema.FieldOptions) string
- func (d *MockDialect) Name() string
- func (d *MockDialect) Placeholder(n int) string
- func (d *MockDialect) Quote(ident string) string
- type MockDriver
- func (d *MockDriver) BeginTx(_ context.Context, _ *driver.TxOptions) (driver.Tx, error)
- func (d *MockDriver) Close() error
- func (d *MockDriver) Dialect() driver.Dialect
- func (d *MockDriver) Exec(ctx context.Context, query string, args ...any) (driver.Result, error)
- func (d *MockDriver) GroveTx(ctx context.Context, isolationLevel int, readOnly bool) (any, error)
- func (d *MockDriver) LastQuery() *RecordedQuery
- func (d *MockDriver) Name() string
- func (d *MockDriver) Open(_ context.Context, _ string, opts ...driver.Option) error
- func (d *MockDriver) Ping(_ context.Context) error
- func (d *MockDriver) Queries() []RecordedQuery
- func (d *MockDriver) Query(ctx context.Context, query string, args ...any) (driver.Rows, error)
- func (d *MockDriver) QueryRow(ctx context.Context, query string, args ...any) driver.Row
- func (d *MockDriver) Reset()
- func (d *MockDriver) SupportsReturning() bool
- type MockResult
- type MockRow
- type MockRows
- type MockTx
- func (t *MockTx) Commit() error
- func (t *MockTx) Exec(ctx context.Context, query string, args ...any) (driver.Result, error)
- func (t *MockTx) Query(ctx context.Context, query string, args ...any) (driver.Rows, error)
- func (t *MockTx) QueryRow(ctx context.Context, query string, args ...any) driver.Row
- func (t *MockTx) Rollback() error
- type RecordedQuery
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertLastArgs ¶
func AssertLastArgs(t *testing.T, d *MockDriver, expected ...any)
AssertLastArgs asserts the args of the last query match.
func AssertLastQuery ¶
func AssertLastQuery(t *testing.T, d *MockDriver, expected string)
AssertLastQuery asserts the last query matches the given string exactly.
func AssertNoQueries ¶
func AssertNoQueries(t *testing.T, d *MockDriver)
AssertNoQueries asserts that no queries were recorded.
func AssertQueryContains ¶
func AssertQueryContains(t *testing.T, d *MockDriver, substring string)
AssertQueryContains asserts that at least one recorded query contains the given substring.
func AssertQueryCount ¶
func AssertQueryCount(t *testing.T, d *MockDriver, n int)
AssertQueryCount asserts that exactly n queries were recorded.
Types ¶
type Fixture ¶
Fixture holds test fixture data.
func LoadFixtures ¶
LoadFixtures reads fixtures from a JSON file. Expected format:
[{"table": "users", "records": [{"name": "Alice"}, ...]}]
type MockDialect ¶
type MockDialect struct{}
MockDialect implements driver.Dialect for testing. It uses PostgreSQL-like syntax by default.
func (*MockDialect) AppendBytes ¶
func (d *MockDialect) AppendBytes(b, v []byte) []byte
func (*MockDialect) AppendTime ¶
func (d *MockDialect) AppendTime(b []byte, t time.Time) []byte
func (*MockDialect) GoToDBType ¶
func (d *MockDialect) GoToDBType(goType reflect.Type, opts schema.FieldOptions) string
func (*MockDialect) Name ¶
func (d *MockDialect) Name() string
func (*MockDialect) Placeholder ¶
func (d *MockDialect) Placeholder(n int) string
func (*MockDialect) Quote ¶
func (d *MockDialect) Quote(ident string) string
type MockDriver ¶
type MockDriver struct {
// ExecFunc optionally handles Exec calls. If nil, returns a default result.
ExecFunc func(ctx context.Context, query string, args ...any) (driver.Result, error)
// QueryFunc optionally handles Query calls. If nil, returns empty rows.
QueryFunc func(ctx context.Context, query string, args ...any) (driver.Rows, error)
// QueryRowFunc optionally handles QueryRow calls. If nil, returns a mock row.
QueryRowFunc func(ctx context.Context, query string, args ...any) driver.Row
// contains filtered or unexported fields
}
MockDriver is an in-memory driver that records queries for testing. It implements driver.Driver but doesn't execute any real queries.
func (*MockDriver) Close ¶
func (d *MockDriver) Close() error
func (*MockDriver) Dialect ¶
func (d *MockDriver) Dialect() driver.Dialect
func (*MockDriver) LastQuery ¶
func (d *MockDriver) LastQuery() *RecordedQuery
LastQuery returns the most recently recorded query, or nil if none.
func (*MockDriver) Name ¶
func (d *MockDriver) Name() string
func (*MockDriver) Queries ¶
func (d *MockDriver) Queries() []RecordedQuery
Queries returns all recorded queries.
func (*MockDriver) SupportsReturning ¶
func (d *MockDriver) SupportsReturning() bool
type MockResult ¶
type MockResult struct {
// contains filtered or unexported fields
}
MockResult implements driver.Result.
func (*MockResult) LastInsertId ¶
func (r *MockResult) LastInsertId() (int64, error)
func (*MockResult) RowsAffected ¶
func (r *MockResult) RowsAffected() (int64, error)
type MockRows ¶
type MockRows struct {
// contains filtered or unexported fields
}
MockRows implements driver.Rows with no data.
type MockTx ¶
type MockTx struct {
// contains filtered or unexported fields
}
MockTx implements driver.Tx.
type RecordedQuery ¶
RecordedQuery holds information about a query executed through the mock driver.