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

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