testrun

package
v0.36.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package testrun contains helper functionality for executing CLI tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestRun

type TestRun struct {
	T *testing.T

	Run    *run.Run
	Out    *bytes.Buffer
	ErrOut *bytes.Buffer
	// contains filtered or unexported fields
}

TestRun is a helper for testing sq commands.

func New

func New(ctx context.Context, t *testing.T, from *TestRun) *TestRun

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.

func (*TestRun) Add

func (tr *TestRun) Add(srcs ...source.Source) *TestRun

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.

func (*TestRun) Bind

func (tr *TestRun) Bind(v any) *TestRun

Bind marshals tr.Out to v (as JSON), failing the test on any error.

func (*TestRun) BindMap

func (tr *TestRun) BindMap() map[string]any

BindMap is a convenience method for binding tr.Out to a map.

func (*TestRun) Exec

func (tr *TestRun) Exec(args ...string) error

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. 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

func (tr *TestRun) Hush() *TestRun

Hush suppresses the printing of output collected in out and errOut to t.Log. Collection to true for tests that output excessive content, binary files, etc.

func (*TestRun) MustReadCSV

func (tr *TestRun) MustReadCSV() [][]string

MustReadCSV reads CSV from tr.Out and returns all records, failing the testing on any problem. Obviously the Exec call should have specified "--csv".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL