testutil

package
v0.20260713.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertNoANSI

func AssertNoANSI(t *testing.T, value string)

func CaptureOutput

func CaptureOutput(fn func()) (string, string)

CaptureOutput captures both stdout and stderr during fn execution. Access is serialized so parallel tests do not race on global descriptors.

func CaptureStdout

func CaptureStdout(fn func()) string

CaptureStdout captures os.Stdout output during fn execution. Access is serialized so parallel tests do not race on global os.Stdout.

func Command

func Command(cmd *cobra.Command, mutators ...OptionsMutator) *cobra.Command

Command applies test options and any requested mutations to a command.

func Fixture

func Fixture(t *testing.T, path string) string

Fixture loads a test fixture from a path relative to the current package.

func JSON

func JSON(t *testing.T, w http.ResponseWriter, data map[string]any)

JSON encodes a success response.

func MustExecute

func MustExecute(t *testing.T, cmd interface{ Execute() error })

MustExecute runs a command in tests and fails immediately on error.

func RawJSON

func RawJSON(t *testing.T, w http.ResponseWriter, body string)

RawJSON writes a literal JSON response body.

func SetColorEnabled

func SetColorEnabled(t *testing.T, enabled bool)

func SetStdoutIsTerminal

func SetStdoutIsTerminal(t *testing.T, enabled bool)

func Setup

func Setup(t *testing.T, handler http.HandlerFunc) *httptest.Server

Setup creates a mock HTTP server and temp config for command tests. Returns the server. Cleanup is automatic via t.Cleanup.

func SetupAdmin added in v0.3.0

func SetupAdmin(t *testing.T, handler http.HandlerFunc) *httptest.Server

SetupAdmin creates a mock admin HTTP server and temp admin config for command tests. Cleanup is automatic via t.Cleanup.

func TestOptions

func TestOptions(mutators ...OptionsMutator) cmdutil.Options

TestOptions returns the default per-command options used by command tests.

func WithOptions

func WithOptions(cmd *cobra.Command, opts cmdutil.Options) *cobra.Command

WithOptions binds explicit options to a command for direct RunE/Execute tests.

Types

type OptionsMutator

type OptionsMutator func(*cmdutil.Options)

func Debug

func Debug(value bool) OptionsMutator

func DryRun

func DryRun(value bool) OptionsMutator

func JQ

func JQ(expr string) OptionsMutator

func JSONOutput

func JSONOutput() OptionsMutator

func NoColor

func NoColor(value bool) OptionsMutator

func NoImage

func NoImage(value bool) OptionsMutator

func NoInput

func NoInput(value bool) OptionsMutator

func NonInteractive added in v0.4.0

func NonInteractive(value bool) OptionsMutator

func PlainOutput

func PlainOutput() OptionsMutator

func Quiet

func Quiet(value bool) OptionsMutator

func Stderr

func Stderr(w io.Writer) OptionsMutator

func Stdin

func Stdin(r io.Reader) OptionsMutator

func Stdout

func Stdout(w io.Writer) OptionsMutator

func Yes

func Yes(value bool) OptionsMutator

Jump to

Keyboard shortcuts

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