Documentation
¶
Overview ¶
Package fakedriver is a minimal in-memory database/sql driver used by the sentrysql tests. It provides three distinct driver shapes:
- CtxDriver: implements driver.Driver and driver.DriverContext; connections satisfy ExecerContext, QueryerContext, ConnPrepareContext, ConnBeginTx, and Pinger.
- LegacyDriver: implements only driver.Driver (no DriverContext); connections implement the pre-context Execer, Queryer, Conn.Begin, and Conn.Prepare.
- MinimalDriver: implements only driver.Driver; connections implement only the required driver.Conn methods (Prepare, Close, Begin). No Execer or Queryer, which forces database/sql to fall back to Prepare + Stmt.Exec/ Stmt.Query, exercising the deepest wrapper fallback paths.
- SkipDriver: implements the context-aware query/exec interfaces but returns driver.ErrSkip from them, forcing database/sql to fall back to prepared statements.
Use NewCtx / NewLegacy / NewMinimal to construct each shape and Register to expose it by name via database/sql.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDriver = errors.New("fakedriver: error")
ErrDriver is a reusable error for failure-injection tests.
Functions ¶
Types ¶
type CtxConnector ¶
type CtxConnector struct {
// contains filtered or unexported fields
}
CtxConnector is an exported connector wrapper backed by a CtxDriver. Unlike the internal ctxConnector returned by CtxDriver.OpenConnector, this one implements io.Closer with an observable close counter so tests can verify that the sentrysql wrapper propagates DB.Close through to inner connectors.
func NewCtxConnector ¶
func NewCtxConnector(drv *CtxDriver) *CtxConnector
NewCtxConnector constructs a CtxConnector.
func (*CtxConnector) Close ¶
func (c *CtxConnector) Close() error
Close implements io.Closer. The counter it increments is observable via CloseCount for verification in tests.
func (*CtxConnector) CloseCount ¶
func (c *CtxConnector) CloseCount() int
CloseCount reports how many times Close was invoked on this connector.
func (*CtxConnector) Driver ¶
func (c *CtxConnector) Driver() driver.Driver
Driver implements driver.Connector.
type CtxDriver ¶
type CtxDriver struct {
// contains filtered or unexported fields
}
CtxDriver is a modern driver that implements driver.DriverContext in addition to driver.Driver. Connections it returns satisfy the full context-aware interface set.
func (*CtxDriver) OpenConnector ¶
OpenConnector implements driver.DriverContext.
func (*CtxDriver) SetFailure ¶
SetFailure makes subsequent Exec/Query calls return err. Pass nil to clear.
type LegacyConnector ¶
type LegacyConnector struct {
// contains filtered or unexported fields
}
LegacyConnector wraps a LegacyDriver as a driver.Connector so tests can exercise the sentrysql wrapper's behavior when a connector's Driver() does not implement driver.DriverContext. It does not implement io.Closer.
func NewLegacyConnector ¶
func NewLegacyConnector(drv *LegacyDriver) *LegacyConnector
NewLegacyConnector constructs a LegacyConnector.
func (*LegacyConnector) Driver ¶
func (c *LegacyConnector) Driver() driver.Driver
Driver implements driver.Connector.
type LegacyDriver ¶
type LegacyDriver struct {
// contains filtered or unexported fields
}
LegacyDriver implements only the pre-context driver.Driver interface.
func (*LegacyDriver) Open ¶
func (d *LegacyDriver) Open(_ string) (driver.Conn, error)
Open implements driver.Driver.
func (*LegacyDriver) SetFailure ¶
func (d *LegacyDriver) SetFailure(err error)
SetFailure makes subsequent Exec/Query calls return err. Pass nil to clear.
type MinimalDriver ¶
type MinimalDriver struct {
// contains filtered or unexported fields
}
MinimalDriver implements only driver.Driver. Connections it returns implement only the required driver.Conn methods — no Execer, Queryer, ConnBeginTx, ConnPrepareContext, or Pinger. Used to exercise the wrapper's deepest fallback path where ExecContext returns driver.ErrSkip and database/sql falls back to Prepare + Stmt.Exec/Stmt.Query.
func (*MinimalDriver) Open ¶
func (d *MinimalDriver) Open(_ string) (driver.Conn, error)
Open implements driver.Driver.
func (*MinimalDriver) SetFailure ¶
func (d *MinimalDriver) SetFailure(err error)
SetFailure makes subsequent Stmt.Exec/Stmt.Query calls return err. Pass nil to clear.
type SkipDriver ¶
type SkipDriver struct{}
SkipDriver forces database/sql to fall back after the context-aware methods return driver.ErrSkip.