testutil

package
v1.43.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureOutStreams added in v1.40.0

func CaptureOutStreams(fn func() error) (string, string, error)

CaptureOutStreams redirects stdout & stderr while running fn and returns the outputs as a string. If there's an error during capture, it returns the error, otherwise it returns the error returned by fn.

func TestCommand added in v1.42.0

func TestCommand(t *testing.T, cmd TestableCommand, cases map[string]TestCase)

Types

type DataType added in v1.42.0

type DataType string
const (
	DataTypeText DataType = "text"
	DataTypeJSON DataType = "json"
	DataTypeYAML DataType = "yaml"
)

type Fixture

type Fixture struct {
	MockController *gomock.Controller
	Client         *hcapi2_mock.MockClient
	ActionWaiter   *state.MockActionWaiter
	TokenEnsurer   *state.MockTokenEnsurer
	Config         *config.MockConfig
}

Fixture provides affordances for testing CLI commands.

func NewFixture

func NewFixture(t *testing.T) *Fixture

NewFixture creates a new Fixture.

func (*Fixture) ExpectEnsureToken

func (f *Fixture) ExpectEnsureToken()

ExpectEnsureToken makes the mock TokenEnsurer expect a EnsureToken call.

func (*Fixture) Finish

func (f *Fixture) Finish()

Finish must be called after the test is finished, preferably via `defer` directly after creating the Fixture.

func (*Fixture) Run

func (f *Fixture) Run(cmd *cobra.Command, args []string) (string, string, error)

Run runs the given cobra command with the given arguments and returns stdout output and a potential error.

func (*Fixture) State added in v1.42.0

func (f *Fixture) State() state.State

State returns a state.State implementation for testing purposes.

type TestCase added in v1.42.0

type TestCase struct {
	Args          []string
	PreRun        func(t *testing.T, fx *Fixture)
	ExpOut        string
	ExpOutType    DataType
	ExpErrOut     string
	ExpErrOutType DataType
}

type TestableCommand added in v1.42.0

type TestableCommand interface {
	CobraCommand(state.State) *cobra.Command
}

Jump to

Keyboard shortcuts

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