Documentation ¶
Index ¶
- type Asserter
- type Assertion
- type Failure
- type GRPCPair
- type LogLevel
- type RequiresTB
- type RunnableTB
- type StepSetter
- type Stepper
- func (ss *Stepper[T]) LevelLog(level, message string, fields map[string]interface{})
- func (ss *Stepper[T]) Log(args ...interface{})
- func (ss *Stepper[T]) PostStepHook(fn func(context.Context, Asserter) error)
- func (ss *Stepper[T]) PreStepHook(fn func(context.Context, Asserter) error)
- func (ss *Stepper[T]) PreVariationHook(fn func(context.Context, Asserter) error)
- func (ss *Stepper[T]) RunSteps(t RunnableTB[T])
- func (ss *Stepper[T]) RunStepsWithContext(ctx context.Context, t RunnableTB[T])
- func (ss *Stepper[T]) Setup(fn callbackErr)
- func (ss *Stepper[_]) Step(desc string, fn func(context.Context, Asserter))
- func (ss *Stepper[_]) Variation(desc string, fn func(context.Context, Asserter))
- type TB
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assertion ¶
type Assertion interface { // Sub creates a named sub-assertion Sub(name string, args ...interface{}) Assertion // T accepts the assertion types like Equal which use generics and therefore // can't be a method of Assertion directly. T(failure *Failure) // NoError asserts that the error is nil, and fails the test if not NoError(err error) // Equal asserts that want == got. If extraLog is set, and the first // argument is a string it is used as a format string for the rest of the // arguments. If the first argument is not a string, everything is just // logged Equal(want, got interface{}) // CodeError asserts that the error returned was non-nil and a Status error // with the given code CodeError(err error, code codes.Code) // NotEmpty asserts that the given values are not nil or zero values (zero // as in reflect.Value.IsZero) NotEmpty(got ...interface{}) // NotNil asserts that the given values are not nil, assessing in order and // stopping at the first nil value (i.e. you can pass thing, thing.field, // thing.field.subfield) NotNil(gots ...interface{}) }
type Failure ¶
type Failure string
func Equal ¶
func Equal[T comparable](want, got T) *Failure
func GreaterThan ¶
func GreaterThan[T constraints.Ordered](a, b T) *Failure
func GreaterThanOrEqual ¶
func GreaterThanOrEqual[T constraints.Ordered](a, b T) *Failure
func LessThan ¶
func LessThan[T constraints.Ordered](a, b T) *Failure
func LessThanOrEqual ¶
func LessThanOrEqual[T constraints.Ordered](a, b T) *Failure
type GRPCPair ¶
type GRPCPair struct { Server *grpc.Server Client *grpc.ClientConn // contains filtered or unexported fields }
func NewGRPCPair ¶
func NewGRPCPair(t TB, middleware ...grpc.UnaryServerInterceptor) *GRPCPair
type RequiresTB ¶
type RequiresTB interface { Helper() Log(args ...interface{}) FailNow() Fail() }
type RunnableTB ¶
type RunnableTB[T RequiresTB] interface { RequiresTB Run(name string, f func(T)) bool }
RunnableTB is the subset of the testing.TB interface which this library requires. Keeping it to a minimum to allow alternate implementations
type StepSetter ¶
type StepSetter interface { // Setup steps run at the start of each RunSteps call, or the start of each // Variation. The context passed to the setup will be canceled after all steps // are completed, or after any fatal error. Setup(fn callbackErr) // PreStepHook runs before every step, after any variations. PreStepHook(fn func(context.Context, Asserter) error) // PreVariationHook runs before every Variation, before any steps. PreVariationHook(fn func(context.Context, Asserter) error) // PostStepHook runs after every step. PostStepHook(fn func(context.Context, Asserter) error) // Step registers a function to make assertions on the running code, this is the // main assertion set. Step(desc string, fn func(context.Context, Asserter)) // Adds a variation to the stepper. Each Variation causes the Setup hooks, // followed by the Variation, then every registered Step (and hooks), allowing // one call to RunSteps to run multiple variations of the same test. Variation(desc string, fn func(context.Context, Asserter)) // LevelLog implements a global logger compatible with pentops/log.go/log. // Log lines will be captured into the currently running test step. LevelLog(level, message string, fields map[string]interface{}) // Log logs any object, it can be used within test callbacks. // Log lines will be captured into the currently running test step. Log(...interface{}) }
StepSetter is a minimal interface to configure the steps and hooks for a test.
type Stepper ¶
type Stepper[T RequiresTB] struct { // contains filtered or unexported fields }
func NewStepper ¶
func NewStepper[T RequiresTB](name string) *Stepper[T]
func (*Stepper[T]) LevelLog ¶
LevelLog implements a global logger compatible with pentops/log.go/log DefaultLogger, and others, to capture log lines from within the handlers into the test output
func (*Stepper[T]) PostStepHook ¶
PostStepHook runs after every step.
func (*Stepper[T]) PreStepHook ¶
PreStepHook runs before every step, after any variations.
func (*Stepper[T]) PreVariationHook ¶
PreVariationHook runs before every Variation, before any steps.
func (*Stepper[T]) RunSteps ¶
func (ss *Stepper[T]) RunSteps(t RunnableTB[T])
RunSteps is the main entry point of the stepper. For each Variation, or just once if no variation is registered, the Setup hooks are run, followed by the Variation, then every registered Step with pre and post hoooks.
func (*Stepper[T]) RunStepsWithContext ¶
func (ss *Stepper[T]) RunStepsWithContext(ctx context.Context, t RunnableTB[T])
RunStepsWithContext allows the caller to provide a context to the stepper.
func (*Stepper[T]) Setup ¶
func (ss *Stepper[T]) Setup(fn callbackErr)
Setup steps run at the start of each RunSteps call, or the start of each Variation. The context passed to the setup will be canceled after all steps are completed, or after any fatal error.
func (*Stepper[_]) Step ¶
Step registers a function to make assertions on the running code, this is the main assertion set.
type TB ¶
type TB interface { //Cleanup(func()) Error(args ...any) Errorf(format string, args ...any) //Fail() FailNow() Failed() bool Fatal(args ...any) Fatalf(format string, args ...any) Helper() Log(args ...any) Logf(format string, args ...any) }
TB is the subset of the testing.TB interface which the stepper's asserter implements.