Documentation
¶
Index ¶
- func AssertChannelEmpty[T any](t *testing.T, ch <-chan T, message string)
- func AssertChannelReceives[T any](t *testing.T, ch <-chan T, timeout time.Duration, message string) T
- func AssertError(t *testing.T, err error, context string)
- func AssertErrorContains(t *testing.T, err error, substring, context string)
- func AssertFileExistsFS(t *testing.T, fs afero.Fs, path string)
- func AssertFileNotExistsFS(t *testing.T, fs afero.Fs, path string)
- func AssertNoError(t *testing.T, err error, context string)
- func CaptureExecCommand(t *testing.T, mocker *CommandMocker) func()
- func ContextWithCancel(t *testing.T) (context.Context, context.CancelFunc)
- func ContextWithDeadline(t *testing.T, deadline time.Time) context.Context
- func ContextWithTimeout(t *testing.T, timeout time.Duration) context.Context
- func Eventually(t *testing.T, condition func() bool, timeout time.Duration, message string)
- func EventuallyWithContext(t *testing.T, ctx context.Context, condition func() bool, message string)
- func FileExistsFS(t *testing.T, fs afero.Fs, path string) bool
- func GoldenJSON(t *testing.T, name string, got interface{})
- func GoldenText(t *testing.T, name string, got string)
- func LoadFixture(t *testing.T, name string) []byte
- func LoadFixtureJSON(t *testing.T, name string, dest interface{})
- func LongContext(t *testing.T) context.Context
- func MatchJSON(expected string) gomock.Matcher
- func MustMarshalJSON(t *testing.T, v interface{}) []byte
- func MustUnmarshalJSON(t *testing.T, data []byte, dest interface{})
- func NewMemFS(t *testing.T) afero.Fs
- func NewOsFS(t *testing.T) (afero.Fs, string)
- func ReadFileFS(t *testing.T, fs afero.Fs, path string) []byte
- func RunParallel(t *testing.T)
- func ShortContext(t *testing.T) context.Context
- func SkipInCI(t *testing.T, reason string)
- func SkipInShort(t *testing.T, reason string)
- func StringContains(substring string) gomock.Matcher
- func TempDir(t *testing.T) string
- func WaitForChannel[T any](t *testing.T, ch <-chan T, timeout time.Duration) T
- func WriteFile(t *testing.T, dir, filename string, data []byte) string
- func WriteFileFS(t *testing.T, fs afero.Fs, path string, data []byte)
- type CommandMocker
- type HTTPMockServer
- func (m *HTTPMockServer) AssertRequestCount(t *testing.T, expected int)
- func (m *HTTPMockServer) AssertRequestMethod(t *testing.T, index int, method string)
- func (m *HTTPMockServer) AssertRequestPath(t *testing.T, index int, path string)
- func (m *HTTPMockServer) GetRequestBody(t *testing.T, index int) []byte
- type JSONMatcher
- type MockCommand
- type MockController
- type StringContainsMatcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertChannelEmpty ¶
AssertChannelEmpty asserts that a channel is empty (non-blocking check)
func AssertChannelReceives ¶
func AssertChannelReceives[T any](t *testing.T, ch <-chan T, timeout time.Duration, message string) T
AssertChannelReceives asserts that a channel receives a value within timeout
func AssertError ¶
AssertError asserts that an error occurred
func AssertErrorContains ¶
AssertErrorContains asserts that an error contains a specific message
func AssertFileExistsFS ¶
AssertFileExistsFS asserts that a file exists in the filesystem
func AssertFileNotExistsFS ¶
AssertFileNotExistsFS asserts that a file does not exist in the filesystem
func AssertNoError ¶
AssertNoError is a convenience wrapper for require.NoError with better error messages
func CaptureExecCommand ¶
func CaptureExecCommand(t *testing.T, mocker *CommandMocker) func()
CaptureExecCommand captures exec.Command calls for testing Usage in tests:
defer CaptureExecCommand(t, mocker)() result := yourFunctionThatCallsExecCommand()
func ContextWithCancel ¶
ContextWithCancel creates a cancellable context with automatic cleanup
func ContextWithDeadline ¶
ContextWithDeadline creates a context with a deadline and automatic cleanup
func ContextWithTimeout ¶
ContextWithTimeout creates a context with a timeout and automatic cleanup
func Eventually ¶
Eventually repeatedly checks a condition until it passes or times out
func EventuallyWithContext ¶
func EventuallyWithContext(t *testing.T, ctx context.Context, condition func() bool, message string)
EventuallyWithContext repeatedly checks a condition with context until it passes or times out
func FileExistsFS ¶
FileExistsFS checks if a file exists in an afero filesystem
func GoldenJSON ¶
GoldenJSON compares JSON output with a golden file or updates it if -update flag is set
func GoldenText ¶
GoldenText compares text output with a golden file or updates it if -update flag is set
func LoadFixture ¶
LoadFixture loads a test fixture file from testdata/fixtures/
func LoadFixtureJSON ¶
LoadFixtureJSON loads and unmarshals a JSON fixture
func LongContext ¶
LongContext creates a context with a 5 second timeout for longer tests
func MustMarshalJSON ¶
MustMarshalJSON marshals a value to JSON or fails the test
func MustUnmarshalJSON ¶
MustUnmarshalJSON unmarshals JSON or fails the test
func ReadFileFS ¶
ReadFileFS reads a file from an afero filesystem
func RunParallel ¶
RunParallel marks a test to run in parallel and returns a cleanup function
func ShortContext ¶
ShortContext creates a context with a short 100ms timeout for fast tests
func SkipInShort ¶
SkipInShort skips a test when running with -short flag
func StringContains ¶
StringContains creates a matcher that matches strings containing the substring
func WaitForChannel ¶
WaitForChannel waits for a channel to receive a value or times out
Types ¶
type CommandMocker ¶
type CommandMocker struct {
Commands map[string]*MockCommand
}
CommandMocker provides a way to mock command executions
func NewCommandMocker ¶
func NewCommandMocker() *CommandMocker
NewCommandMocker creates a new command mocker
func (*CommandMocker) Get ¶
func (m *CommandMocker) Get(cmdName string) (*MockCommand, bool)
Get retrieves a mock command by name
func (*CommandMocker) Mock ¶
func (m *CommandMocker) Mock(cmdName string, stdout, stderr string, exitCode int)
Mock registers a mock response for a command
func (*CommandMocker) MockError ¶
func (m *CommandMocker) MockError(cmdName, stderr string, exitCode int)
MockError registers a failed command execution
func (*CommandMocker) MockSuccess ¶
func (m *CommandMocker) MockSuccess(cmdName, stdout string)
MockSuccess registers a successful command execution
type HTTPMockServer ¶
type HTTPMockServer struct {
*httptest.Server
Requests []*http.Request // Record all requests
Bodies [][]byte // Record all request bodies
// contains filtered or unexported fields
}
HTTPMockServer creates a test HTTP server with custom handlers
func NewHTTPMockServer ¶
func NewHTTPMockServer(t *testing.T, handler http.HandlerFunc) *HTTPMockServer
NewHTTPMockServer creates a new mock HTTP server with the given handler
func NewJSONMockServer ¶
func NewJSONMockServer(t *testing.T, statusCode int, response interface{}) *HTTPMockServer
NewJSONMockServer creates a mock server that responds with JSON
func (*HTTPMockServer) AssertRequestCount ¶
func (m *HTTPMockServer) AssertRequestCount(t *testing.T, expected int)
AssertRequestCount asserts the number of requests received
func (*HTTPMockServer) AssertRequestMethod ¶
func (m *HTTPMockServer) AssertRequestMethod(t *testing.T, index int, method string)
AssertRequestMethod asserts the HTTP method of a specific request
func (*HTTPMockServer) AssertRequestPath ¶
func (m *HTTPMockServer) AssertRequestPath(t *testing.T, index int, path string)
AssertRequestPath asserts the path of a specific request
func (*HTTPMockServer) GetRequestBody ¶
func (m *HTTPMockServer) GetRequestBody(t *testing.T, index int) []byte
GetRequestBody returns the body of a specific request
type JSONMatcher ¶
type JSONMatcher struct {
// contains filtered or unexported fields
}
JSONMatcher matches JSON strings with flexible comparison
func (*JSONMatcher) Matches ¶
func (m *JSONMatcher) Matches(x interface{}) bool
func (*JSONMatcher) String ¶
func (m *JSONMatcher) String() string
type MockCommand ¶
MockCommand represents a mock command execution
type MockController ¶
type MockController struct {
*gomock.Controller
}
MockController wraps gomock.Controller with automatic cleanup
func NewMockController ¶
func NewMockController(t *testing.T) *MockController
NewMockController creates a new mock controller with automatic cleanup
type StringContainsMatcher ¶
type StringContainsMatcher struct {
// contains filtered or unexported fields
}
StringContainsMatcher matches strings containing a substring
func (*StringContainsMatcher) Matches ¶
func (m *StringContainsMatcher) Matches(x interface{}) bool
func (*StringContainsMatcher) String ¶
func (m *StringContainsMatcher) String() string