Documentation
¶
Overview ¶
Package itertest provides facilities for testing internal iterators.
Index ¶
- Variables
- func Attach(iter base.InternalIterator, initialState ProbeState, probes ...Probe) base.InternalIterator
- func Condensed(opts *iterCmdOpts)
- func NewParser() *dsl.Parser[Probe]
- func RunInternalIterCmd(t *testing.T, d *datadriven.TestData, iter base.InternalIterator, ...) string
- func RunInternalIterCmdWriter(t *testing.T, w io.Writer, d *datadriven.TestData, iter base.InternalIterator, ...)
- func ShowCommands(opts *iterCmdOpts)
- func Verbose(opts *iterCmdOpts)
- type ErrorProbe
- type IterOpt
- type Op
- type OpKind
- type Predicate
- type Probe
- type ProbeContext
- type ProbeState
- type UserKey
Constants ¶
This section is empty.
Variables ¶
var ErrInjected = Error("ErrInjected", errorfs.ErrInjected)
ErrInjected is an error artificially injected for testing.
Functions ¶
func Attach ¶
func Attach( iter base.InternalIterator, initialState ProbeState, probes ...Probe, ) base.InternalIterator
Attach takes an iterator, an initial state and a probe, returning an iterator that will invoke the provided Probe on all internal iterator operations.
func Condensed ¶
func Condensed(opts *iterCmdOpts)
Condensed configures RunInternalIterCmd to output condensed results without values, collapsed onto a single line.
func RunInternalIterCmd ¶
func RunInternalIterCmd( t *testing.T, d *datadriven.TestData, iter base.InternalIterator, opts ...IterOpt, ) string
RunInternalIterCmd evaluates a datadriven command controlling an internal iterator, returning a string with the results of the iterator operations.
func RunInternalIterCmdWriter ¶
func RunInternalIterCmdWriter( t *testing.T, w io.Writer, d *datadriven.TestData, iter base.InternalIterator, opts ...IterOpt, )
RunInternalIterCmdWriter evaluates a datadriven command controlling an internal iterator, writing the results of the iterator operations to the provided Writer.
func ShowCommands ¶
func ShowCommands(opts *iterCmdOpts)
ShowCommands configures RunInternalIterCmd to show the command in each output line (so you don't have to visually match the line to the command).
Types ¶
type ErrorProbe ¶
type ErrorProbe struct {
// contains filtered or unexported fields
}
ErrorProbe is a Probe that injects an error.
func Error ¶
func Error(name string, err error) *ErrorProbe
Error returns a Probe that returns the provided error. The name is Name returned by String().
func (*ErrorProbe) Error ¶
func (p *ErrorProbe) Error() error
Error implements error, so that injected error values may be used as probes that inject themselves.
func (*ErrorProbe) Probe ¶
func (p *ErrorProbe) Probe(pctx *ProbeContext)
Probe implements the Probe interface, replacing the iterator return value with an error.
type IterOpt ¶
type IterOpt func(*iterCmdOpts)
An IterOpt configures the behavior of RunInternalIterCmd.
func WithSpan ¶
WithSpan configures RunInternalIterCmd to print the span returned by spanFunc after each iteration operation.
func WithStats ¶
func WithStats(stats *base.InternalIteratorStats) IterOpt
WithStats configures RunInternalIterCmd to collect iterator stats in the struct pointed to by stats.
type Op ¶
type Op struct {
Kind OpKind
SeekKey []byte
// Return is initialized with the return result of the underlying iterator.
// Probes may mutate them.
Return struct {
KV *base.InternalKV
Err error
}
}
Op describes an individual iterator operation being performed.
type OpKind ¶
type OpKind int8
OpKind indicates the type of iterator operation being performed.
const ( // OpSeekGE indicates a SeekGE internal iterator operation. OpSeekGE OpKind = iota // OpSeekPrefixGE indicates a SeekPrefixGE internal iterator operation. OpSeekPrefixGE // OpSeekLT indicates a SeekLT internal iterator operation. OpSeekLT // OpFirst indicates a First internal iterator operation. OpFirst // OpLast indicates a Last internal iterator operation. OpLast // OpNext indicates a Next internal iterator operation. OpNext // OpNextPrefix indicates a NextPrefix internal iterator operation. OpNextPrefix // OpPrev indicates a Prev internal iterator operation. OpPrev // OpClose indicates a Close internal iterator operation. OpClose )
func (OpKind) Evaluate ¶
func (o OpKind) Evaluate(pctx *ProbeContext) bool
Evaluate implements Predicate.
type Predicate ¶
type Predicate = dsl.Predicate[*ProbeContext]
Predicate encodes conditional logic that yields a boolean.
type Probe ¶
type Probe interface {
// Probe inspects, and possibly manipulates, iterator operations' results.
Probe(*ProbeContext)
}
Probe defines an interface for probes that may inspect or mutate internal iterator behavior.
func If ¶
If a conditional Probe. If its predicate evaluates to true, it probes using its Then probe. If its predicate evalutes to false, it probes using its Else probe.
func MustParseProbes ¶
MustParseProbes parses each DSL string as a separate probe, returning a slice of parsed probes. Panics if any of the probes fail to parse.
func ReturnKV ¶
func ReturnKV(kv *base.InternalKV) Probe
ReturnKV returns a Probe that modifies an operation's return value to the provided KV pair.
type ProbeContext ¶
type ProbeContext struct {
Op
ProbeState
}
ProbeContext provides the context within which a Probe is run. It includes information about the iterator operation in progress.
type ProbeState ¶
ProbeState holds state additional to the context of the operation that's accessible to probes.