Documentation
¶
Overview ¶
Package testutils provides utility functions for testing and test assertions.
Index ¶
- func AssertContains(t TestingT, str, substr string, msgAndArgs ...interface{})
- func AssertDeepEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})
- func AssertEqual[T comparable](t TestingT, expected, actual T, msgAndArgs ...interface{})
- func AssertError(t TestingT, err error, msgAndArgs ...interface{})
- func AssertErrorType[T error](t TestingT, err error, msgAndArgs ...interface{})
- func AssertEventuallyTrue(t TestingT, condition func() bool, timeout time.Duration, ...)
- func AssertFalse(t TestingT, condition bool, msgAndArgs ...interface{})
- func AssertNil(t TestingT, value interface{}, msgAndArgs ...interface{})
- func AssertNoError(t TestingT, err error, msgAndArgs ...interface{})
- func AssertNotContains(t TestingT, str, substr string, msgAndArgs ...interface{})
- func AssertNotEqual[T comparable](t TestingT, expected, actual T, msgAndArgs ...interface{})
- func AssertNotNil(t TestingT, value interface{}, msgAndArgs ...interface{})
- func AssertNotPanics(t TestingT, fn func(), msgAndArgs ...interface{})
- func AssertPanics(t TestingT, fn func(), msgAndArgs ...interface{})
- func AssertTrue(t TestingT, condition bool, msgAndArgs ...interface{})
- func BenchmarkFunction(fn func(), iterations int) time.Duration
- func CaptureOutput(fn func()) (stdout, stderr string)
- func CreateTempDir(t *testing.T, pattern string) string
- func CreateTempFile(t *testing.T, pattern, content string) string
- func GetCallerInfo(skip int) (filename string, lineNumber int)
- func MockHTTPServer(responses map[string]MockResponse) *httptest.Server
- type MockResponse
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertContains ¶
AssertContains asserts that a string contains a substring.
func AssertDeepEqual ¶
func AssertDeepEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})
AssertDeepEqual asserts that two values are deeply equal using reflection.
func AssertEqual ¶
func AssertEqual[T comparable](t TestingT, expected, actual T, msgAndArgs ...interface{})
AssertEqual asserts that two values are equal.
func AssertError ¶
AssertError asserts that an error is not nil.
func AssertErrorType ¶
AssertErrorType asserts that an error is of a specific type.
func AssertEventuallyTrue ¶
func AssertEventuallyTrue(t TestingT, condition func() bool, timeout time.Duration, msgAndArgs ...interface{})
AssertEventuallyTrue asserts that a condition becomes true within a timeout.
func AssertFalse ¶
AssertFalse asserts that a condition is false.
func AssertNil ¶
func AssertNil(t TestingT, value interface{}, msgAndArgs ...interface{})
AssertNil asserts that a value is nil.
func AssertNoError ¶
AssertNoError asserts that an error is nil.
func AssertNotContains ¶
AssertNotContains asserts that a string does not contain a substring.
func AssertNotEqual ¶
func AssertNotEqual[T comparable](t TestingT, expected, actual T, msgAndArgs ...interface{})
AssertNotEqual asserts that two values are not equal.
func AssertNotNil ¶
func AssertNotNil(t TestingT, value interface{}, msgAndArgs ...interface{})
AssertNotNil asserts that a value is not nil.
func AssertNotPanics ¶
func AssertNotPanics(t TestingT, fn func(), msgAndArgs ...interface{})
AssertNotPanics asserts that a function does not panic.
func AssertPanics ¶
func AssertPanics(t TestingT, fn func(), msgAndArgs ...interface{})
AssertPanics asserts that a function panics.
func AssertTrue ¶
AssertTrue asserts that a condition is true.
func BenchmarkFunction ¶
BenchmarkFunction benchmarks a function and returns the duration per operation.
func CaptureOutput ¶
func CaptureOutput(fn func()) (stdout, stderr string)
CaptureOutput captures stdout/stderr output from a function.
func CreateTempDir ¶
CreateTempDir creates a temporary directory for testing.
func CreateTempFile ¶
CreateTempFile creates a temporary file for testing.
func GetCallerInfo ¶
GetCallerInfo returns information about the calling function.
func MockHTTPServer ¶
func MockHTTPServer(responses map[string]MockResponse) *httptest.Server
MockHTTPServer creates a mock HTTP server for testing.
Types ¶
type MockResponse ¶
type MockResponse struct {
StatusCode int
Headers map[string]string
Body string
JSONBody interface{}
}
MockResponse represents a mock HTTP response.
func NewMockResponse ¶
func NewMockResponse(statusCode int) MockResponse
NewMockResponse creates a new mock response.
func (MockResponse) WithBody ¶
func (m MockResponse) WithBody(body string) MockResponse
WithBody sets the response body.
func (MockResponse) WithHeader ¶
func (m MockResponse) WithHeader(key, value string) MockResponse
WithHeader adds a header to the mock response.
func (MockResponse) WithJSONBody ¶
func (m MockResponse) WithJSONBody(data interface{}) MockResponse
WithJSONBody sets the response body as JSON.