Help us shape the future of Go! Take the 2026 Go Developer Survey

iowriter

package
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Eventf added in v1.19.0

func Eventf(t Logger, format string, args ...any)

Eventf records something the framework did, as opposed to something a process printed. Events share the report of the process output they interleave with, and like it are only shown when the test fails.

func LogDir added in v1.19.0

func LogDir() string

LogDir is the directory reports are written to. It is deliberately outside t.TempDir() so that the files survive the test run that produced them.

func NewMultiWriteCloser added in v1.18.3

func NewMultiWriteCloser(ws ...io.WriteCloser) io.WriteCloser

NewMultiWriteCloser returns an io.WriteCloser which duplicates its writes to all the provided WriteClosers, and closes them all on Close.

func Notef added in v1.19.0

func Notef(t Logger, format string, args ...any)

Notef records a message shown at the top of the report. Reserve it for conditions which explain an entire failure, such as a blown deadline.

func RedirectInProcessLogs added in v1.19.0

func RedirectInProcessLogs() (string, func(), error)

RedirectInProcessLogs sends the output of code running inside the test binary itself, rather than inside a process a test started, to a file. It reports where it wrote.

This output belongs to no particular test, so the framework cannot attribute it to one, and it lands on the terminal in the middle of a run. Two sources produce it:

  • dapr's own logger, which packages such as pkg/security register at init and which writes to stderr;
  • the standard library logger, used directly by a handful of test apps and, more importantly, by net/http for things like "TLS handshake error" when a server has no ErrorLog of its own.

Only dapr loggers already registered are redirected. Packages register theirs at init, so calling this before the run starts covers them; a logger created later still writes to stderr. The standard library redirect has no such caveat, since there is a single logger behind log.Printf.

Set DAPR_INTEGRATION_INPROCESS_LOGS to leave everything on stderr.

The returned function points the standard library logger back where it was. It deliberately leaves the dapr loggers pointing at the file: putting them back would mean calling ApplyOptionsToLoggers a second time, which rewrites every registered logger, and a worker goroutine outliving its test can still be logging through one of them by then.

func Reset added in v1.19.0

func Reset() error

Reset clears the state of the previous run: the recorded failures, and the log files, so that `less <dir>/*.log` shows this run and not the last one. Concurrent runs on one machine should set DAPR_INTEGRATION_LOGS_DIR to keep out of each other's way.

Both matter under `go test -count=N`, which runs the suite N times in one process. Without this, run two reports run one's failures as its own.

Only files this package wrote are removed. DAPR_INTEGRATION_LOGS_DIR may point anywhere, so emptying the directory wholesale is not something to do.

Types

type Failure added in v1.19.0

type Failure struct {
	Test string
	Path string
}

Failure is a test which produced a log report, and the file it was written to.

func Failures added in v1.19.0

func Failures() []Failure

Failures returns every test which wrote a report, in the order they finished.

type Logger

type Logger interface {
	Log(args ...any)
	Name() string
	Cleanup(func())
	Failed() bool
	Output() io.Writer
}

Logger is the subset of *testing.T needed to capture and report test output. Output is used rather than Log so that captured lines are not stamped with the source location of this package.

type WriteCloser added in v1.19.0

type WriteCloser interface {
	io.WriteCloser
	Name() string

	// Stream returns a second writer reporting under the same name, for another
	// stream of the same process.
	Stream() WriteCloser
}

WriteCloser captures the output of a single process. Name reports the label the output is reported under, which may differ from the requested name when several instances of the same process take part in a test.

func New

func New(t Logger, procName string) WriteCloser

New returns a writer which captures the output of procName for t. Calling it more than once with the same name for the same test appends an index to the name, so that multiple instances of a process stay distinguishable.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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