Documentation
¶
Overview ¶
Package testutils provides utilities for capturing output, managing test files, and making assertions in tests.
Index ¶
- func AssertContainsAll(t *testing.T, contents string, elements []string)
- func AssertContainsNone(t *testing.T, contents string, elements []string)
- func AssertFileContains(t *testing.T, filePath string, want []string, notWant []string)
- func AssertFileContentsSameAs(t *testing.T, wantFilePath string, gotFilePath string)
- func AssertNotBlank(t *testing.T, value string)
- func CaptureStdout(t *testing.T, fn func()) (stdout string)
- func CreateMockFile(t *testing.T, namePattern string, contents []byte) string
- func CreateMockServer(t *testing.T, responses map[string]MockHTTPResponse) *httptest.Server
- func CreateOpenNewTestFile(t *testing.T, namePattern string) *os.File
- func Ptr[T any](value T) *T
- func ReadFile(t *testing.T, filePath string) []byte
- func SyncCall(lock *sync.Mutex, fn func())
- func WithArgs(_ *testing.T, fn func(), args ...string)
- type MockHTTPResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertContainsAll ¶
AssertContainsAll verifies that the given contents string contains all specified elements.
func AssertContainsNone ¶
AssertContainsNone verifies that the given contents string contains none of the specified elements.
func AssertFileContains ¶
AssertFileContains checks if a file contains all strings from want slice and none from notWant slice.
func AssertFileContentsSameAs ¶
AssertFileContentsSameAs verifies that two files have identical contents.
func AssertNotBlank ¶
AssertNotBlank asserts that the given string is not blank (i.e., not empty or consisting only of whitespace).
func CaptureStdout ¶
CaptureStdout captures standard output during the execution of the provided function and returns it as a string. This function is synchronized to prevent concurrent stdout capture.
func CreateMockFile ¶
CreateMockFile creates a temporary file with the given name pattern and contents, returning the file path.
func CreateMockServer ¶
CreateMockServer creates a test HTTP server with configurable responses. It accepts a map of paths to response configurations (status code and content). Returns the server which should be closed after use.
func CreateOpenNewTestFile ¶
CreateOpenNewTestFile creates and opens a new temporary test file with the given name pattern. The caller is responsible for closing the file.