Documentation ¶
Overview ¶
Package testrun contains helper functionality for executing CLI tests.
Index ¶
- type TestRun
- func (tr *TestRun) Add(srcs ...source.Source) *TestRun
- func (tr *TestRun) Bind(v any) *TestRun
- func (tr *TestRun) BindCSV() [][]string
- func (tr *TestRun) BindMap() map[string]any
- func (tr *TestRun) BindSliceMap() []map[string]any
- func (tr *TestRun) BindYAML(v any) *TestRun
- func (tr *TestRun) Exec(args ...string) error
- func (tr *TestRun) Hush() *TestRun
- func (tr *TestRun) OutString() string
- func (tr *TestRun) Reset() *TestRun
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TestRun ¶
type TestRun struct { T testing.TB Context context.Context Run *run.Run // Out contains the output written to stdout after TestRun.Exec is invoked. Out *bytes.Buffer // ErrOut contains the output written to stderr after TestRun.Exec is invoked. ErrOut *bytes.Buffer // contains filtered or unexported fields }
TestRun is a helper for testing sq commands.
func New ¶
New returns a new run instance for testing sq commands. If from is non-nil, its config is used. This allows sequential commands to use the same config.
You can also use TestRun.Reset to reuse a TestRun instance.
func (*TestRun) Add ¶
Add adds srcs to tr.Run.Config.Collection. If the collection does not already have an active source, the first element of srcs is used as the active source.
REVISIT: Why not use *source.Source instead of the value?
func (*TestRun) BindCSV ¶ added in v0.41.0
BindCSV reads CSV from tr.Out and returns all records, failing the testing on any problem. Obviously the Exec call should have specified "--csv".
func (*TestRun) BindMap ¶
BindMap is a convenience method for binding tr.Out to a map (assuming tr.Out is JSON).
func (*TestRun) BindSliceMap ¶ added in v0.41.0
BindSliceMap is a convenience method for binding tr.Out to a slice of map (assuming tr.Out is JSON).
func (*TestRun) BindYAML ¶ added in v0.44.0
BindYAML marshals tr.Out to v (as YAML), failing the test on any error.
func (*TestRun) Exec ¶
Exec executes the sq command specified by args. If the first element of args is not "sq", that value is prepended to the args for execution. This method may only be invoked once on this TestRun instance, unless TestRun.Reset is called. The backing Run will also be closed. If an error occurs on the client side during execution, that error is returned. Either tr.Out or tr.ErrOut will be filled, according to what the CLI outputs.
func (*TestRun) Hush ¶
Hush suppresses the printing of output collected in out and errOut to t.Log. Set to true for tests that output excessive content, binary files, etc.