Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TempDir ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.