fs

package
v0.33.3 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TempDir

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

TempDir creates a temporary directory that will be removed if the tests passes. The temporary directory is created by joining all elements from path, with the sanitised test name.

If path is empty, the temporary directory is created in os.TempDir.

When tests are run with -v, the temporary directory absolute path will be logged.

This function differs from the stdlib TempDir because when the test fails:

  • the path to the created directly is logged
  • the directory is not removed

Types

type LogFile

type LogFile struct {
	*os.File
	// contains filtered or unexported fields
}

LogFile wraps a *os.File and makes it more suitable for tests. Methods to search and wait for substrings in lines are provided, they keep track of the offset, ensuring ordering when when searching.

func NewLogFile

func NewLogFile(t testing.TB, dir, pattern string) *LogFile

NewLogFile returns a new LogFile which wraps a os.File meant to be used for testing. Methods to search and wait for strings in the file are provided. 'dir' and 'pattern' are passed directly to os.CreateTemp. It is the callers responsibility to remove the file. To keep the file when the test fails, use TempDir to create a folder.

func (*LogFile) FindInLogs

func (l *LogFile) FindInLogs(str string) (bool, error)

FindInLogs searches for str in the log file keeping track of the offset. It returns true if str is found in the logs. If there are any errors, it returns false and the error

func (*LogFile) LogContains

func (l *LogFile) LogContains(t testing.TB, str string)

LogContains searches for str in the log file keeping track of the offset. If there is any issue reading the log file, then t.Fatalf is called, if str is not present in the logs, t.Errorf is called.

func (*LogFile) ResetOffset

func (l *LogFile) ResetOffset()

ResetOffset resets the log file offset

func (*LogFile) WaitLogsContains

func (l *LogFile) WaitLogsContains(t testing.TB, s string, timeout time.Duration, msgAndArgs ...any)

WaitLogsContains waits for the specified string s to be present in the logs within the given timeout duration and fails the test if s is not found. It keeps track of the log file offset, reading only new lines. Each subsequent call to WaitLogsContains will only check logs not yet evaluated. msgAndArgs should be a format string and arguments that will be printed if the logs are not found, providing additional context for debugging.

Jump to

Keyboard shortcuts

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