testutil

package
v1.44.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
	Terminal       *terminal.MockTerminal
}

Fixture provides affordances for testing CLI commands.

func NewFixture

func NewFixture(t *testing.T) *Fixture

NewFixture creates a new Fixture with default config file.

func NewFixtureWithConfigFile added in v1.44.0

func NewFixtureWithConfigFile(t *testing.T, f any) *Fixture

NewFixtureWithConfigFile creates a new Fixture with the given config file. See config.Config.Read for the supported types of f.

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
}

Directories

Path Synopsis
Package terminal is a generated GoMock package.
Package terminal is a generated GoMock package.

Jump to

Keyboard shortcuts

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