testutil

package
v1.41.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: MIT Imports: 12 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 MockResponse added in v1.40.0

func MockResponse[V any](v V) (*hcloud.Response, error)

MockResponse returns a *hcloud.Response with the given value as JSON body.

Types

type Fixture

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

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.

Jump to

Keyboard shortcuts

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