testutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package testutil provides shared test helpers for the go-bricks-openapi tool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureStdout

func CaptureStdout(t *testing.T, fn func()) string

CaptureStdout runs fn with os.Stdout redirected to a pipe and returns what was printed there. Several subcommands write progress via fmt.Printf (os.Stdout), which cobra's SetOut does not intercept, so capturing the real os.Stdout is the only way to observe that output in tests.

The pipe is drained in a goroutine so a large write can't deadlock; the write end is closed even if fn panics (so the drain goroutine reaches EOF and terminates instead of leaking), and the read end is closed once drained (no fd leak).

NOTE: mutates the global os.Stdout; do not call from parallel tests.

Types

This section is empty.

Jump to

Keyboard shortcuts

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